当前位置:网站首页>Assembly language learning (2)
Assembly language learning (2)
2022-08-09 14:50:00 【The goal is a tech house】
I learned about Wang Shuang today《汇编语言》第5、6章.
I feel that these two chapters mainly deepen the for段这个概念的理解.
第5章[Bx]和loop指令,重点在于Understanding of segment addresses and offset addresses,段前缀的应用.
第6Chapters contain programs with multiple segments,重点在于Understand why segmenting is required,Learn how to write segmented assembler,Figure out how segments are stored in memory.
1.loop指令和[bx]的应用
1.1 计算ffff:0~ffff:bThe sum of the data in the cell,并将结果保存在dx中?
存在的问题:8The accumulated sum of the memory cells of the bits is placed16位的寄存器中.
解决的方法:以ax为中介,其中ah设为0,alis the value of the memory unit.
mov ax,0ffffh里面,0和h一个都不能少.
assume cs:code
code segment
mov ax,0ffffh
mov ds,ax
mov ax,0
mov dx,0
mov bx,0
mov cx,12
s:mov al,[bx]
add dx,ax
inc bx
loop s
mov ax,4c00h
int 21h
code ends
end1.2 将内存ffff:0~ffff:b单元中的数据复制到0:200~0:20b中?
段前缀的应用,ds、cs、ss、es都可以使用,很灵活.
注意题目是,将内存ffff:0~ffff:b单元中的数据复制到0:200~0:20b单元中.Set the segment prefix to 0020h比0要方便.
mov ax,0ffffh
mov ds,ax
mov ax,0020h
mov es,ax
mov bx,0
mov cx,12
s: mov dl,[bx]
mov es:[bx],dl
inc bx
loop s2.包含多个段的程序
2.1 How to accumulate data?
That is, how some data constants should be declared,如何引用?
采用dw 0123h,0456h,0789h进行声明.
通过cs:[bx]进行定位,bx每次增加2个字节.
But just make these changes,Problems arise at runtime.Take a look at the program's memory first:

可以看出前6bytes store the value of three words,To avoid treating data as instructions,程序应该从0C53:0006开始执行.
So it needs to be used in the source programend标号,The entry address of the marked program.
2.2 利用栈,Store the data defined in the program in reverse?
首先,Declare a space ahead of time,for stack use.
另外,Set the segment address and offset address of the stack.
示例程序如下:
assume cs:code
code segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
dd 0,0,0,0,0,0,0,0
start:mov ax,cs
mov ss,ax
mov sp,30h
mov bx,0
mov cx,8
s: push cs:[bx]
add bx,2
loop s
mov bx,0
mov cx,8
s1:pop cs:[bx]
add bx,2
loop s1
mov ax,4c00h
int 21h
code ends
end start2.3 结构更清晰——Divide the code into multiple segments
Below is the example mentioned earlier,Don't overstate the data、Stack and code three segments.
需要注意的是:
1.在assume之后,CPU不会将CS指向code,不会将DS指向data,不会将SS指向stack.
2.endIndicates the entry of the program,这个入口将被写入可执行文件的描述信息.After the program in the executable is loaded into memory,CPU的CS:IP被设置指向这个入口,Start executing the first instruction in the program.
所以,CSThe value does not need to be set in the code,但是DS和SSThe value of needs to be explained in the code.
3.对于一个段,如果段中的数据占N个字节,则程序加载后,该段实际占有的空间为:
(N/256+1)*256
where division rounds up.
assume cs:code,ds:data,ss:stack
data segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
data ends
stack segment
dw 0,0,0,0,0,0,0,0
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,20h
mov ax,data
mov ds,ax
mov bx,0
mov cx,8
s: push [bx]
add bx,2
loop s
mov bx,0
mov cx,8
s1: pop [bx]
add bx,2
loop s1
mov ax,4c00h
int 21h
code ends
end startDebug by yourself,Discover how segments are stored in memory,It's an interesting thing.
But the more interesting things are always behind(手动滑稽)
边栏推荐
- 汇编语言学习(十)常用指令总结
- 除了开心麻花,中国喜剧还有什么?
- 面试官:请说说什么是BFC?大白话讲清楚
- 关于舵机的漂移与不听指挥乱动的问题
- C语言 求一个整数存储在内存中的二进制中1的个数(多种方法详解)
- 微信小程序getPhoneNumber接口code=40013
- 【ICDE 2022】阿里发布稀疏模型训练框架HybridBackend,单位成本下训练吞吐提升至5倍
- 使用 compose 的 Canvas 自定义绘制实现 LCD 显示数字效果
- ELK deployment
- 11. cuBLAS Development Guide Chinese version--Level-1 functions amax() and amin() in cuBLAS
猜你喜欢
随机推荐
递归实现汉诺塔问题
湖仓一体,Hologres加速云数据湖DLF技术原理解析
Analysis of SEATA Distributed Transaction Framework
曾毓群想做王传福
11. cuBLAS Development Guide Chinese version--Level-1 functions amax() and amin() in cuBLAS
What are the steps website small program development?
汇编语言学习(七)
flink并行度知识点
汇编语言学习(六)课程设计一
面试官:请说说什么是BFC?大白话讲清楚
#23-5 OJ 86 杨辉三角形
RHCE课程总结
CTF题解五 Web PHP大法(实验吧)
#25-1 OJ 78 Calculate birthday day of the week
探索快八年,谁挡住了小红书的电商梦?
System Scalability Thinking
【ICDE 2022】阿里发布稀疏模型训练框架HybridBackend,单位成本下训练吞吐提升至5倍
C语言 三子棋(含完整 代码详解)
From the Dutch flag problem to the optimization and upgrade of quick row
现实版商战:“武功再高,也怕菜刀”









