当前位置:网站首页>Assembly language learning (1)
Assembly language learning (1)
2022-08-09 14:50:00 【The target is a technology curtilage】
In the past two days, I have studied the first three chapters of Wang Shuang's "Assembly Language", and summarized some points that I think are interesting.
1. byte unit and word unit
A memory unit is a byte unit with 8 bits.
A word unit is equal to two byte units and has 16 bits.
The storage of word units in memory, for example, the storage of 2345, 6789:
| Address | Data |
|---|---|
| 20000h | 45h |
| 20001h | 23h |
| 20002h | 89h |
| 20003h | 67h |
2345h, the high-order bit is 23h, and there is a unit with a large address.The lower bit is 45h, and there is a unit with a small address.
Generally speaking, when the word unit is read, it is read two by two.For example, when the number 2345h is placed in the register, the following syntaxes are generally used:
mov ax,2345h
Store directly into a 16-bit register.
mov ax,[0000]
When the segment address is ds, one word unit and two bytes are stored according to the offset address.
You can also save it in 8923h if you are thinking about it.
mov ax,[0001]
What if you only want to store one byte?
mov ah,[0000]
Only one byte is stored in the high-order part of the register ah, of course, it can also be stored in the low-order part of al.
2. segment address
As needed, a segment of memory can be defined as a segment, which can be data segment, code segment and stack segment.
1. data segment
The segment address of the data segment is placed in ds.
The CPU accesses ds:[0000] every time an instruction to access a memory unit, such as mov ax,[0000], is executed.
2.Code snippet
The segment address of the code segment is placed in cs, and the offset address is placed in ip.
The CPU will start executing instructions at the location of cs:ip every time.
3. stack segment
The segment address of the stack segment is placed in ss, and the offset address is placed in sp.
Every time a push, pop operation is performed, the CPU will execute the command according to the principle of first-in, last-out.
Where these paragraphs begin and end is determined by humans.Especially the stack segment, the CPU actually only provides a pointer, you must be clear about the scope of your own arrangement of space.Otherwise, stack overflow or stack underflow will occur, resulting in overwriting the original content or other situations.
3. About the stack segment
1. push and pop
These two commands are still interesting.
What does thepush operation mean?
If you want to put the nth element on the stack, then the initial sp pointer points to the n-1th element.
After the push ax operation, first sp = sp - 2, and then put the value in ax into sp to the address currently pointed to.
pop operation means, first assign the value in the current word unit to the register, then sp = sp + 2.
It is important to remember that the stack grows from high address to low address.
2. Exercise questions about push and pop
There is a nice topic in the book to help understand the process of these two operations:
Write font data 2266h at 10000h, and commands such as mov memory unit, register cannot be used. To put it bluntly, it is to use the stack method.
mov ax,1000span>mov ss,axmov sp,2mov ax,2266push axWhat's interesting is that initially sp needs to point to 2 instead of 0.Because sp will move up two positions in the push operation, and the data will be stored at 10000h.
If you want to pop out the data at the 10000h position, mov sp,0 is enough.
3. Exercise questions about the length of the stack segment
1.If the space 10000h~1FFFFh is regarded as a stack segment, the initial stack is empty, SS=1000h, SP=?
sp = 0
This is actually easy to understand, sp - 2 is equal to FFFEh, just understand this.
2.What is the maximum size of a stack segment?
For SP and IP, the value range is 0~FFFFh.
For a stack segment, wrapping occurs when the stack is full, so the maximum size is 64KB.
It feels that the value range of other segments will not exceed 64KB.
边栏推荐
猜你喜欢
随机推荐
【视频编码学习】——变换的理解
PerparedStatement防止SQL注入
*1-1 OJ 56 Hamming Distance
RHCE Course Summary
Operating system migration practice deploying MySQL database on openEuler
flink并行度知识点
Which applet making software is easy to use?how to choose?
ELK部署
“未来10年,中国APP不可能回印度了”
How to develop small programs?should focus on features
202五一杯数学建模ABC三题
11. cuBLAS Development Guide Chinese version--Level-1 functions amax() and amin() in cuBLAS
display:inline-block 什么时候不会显示间隙?
RHCE Course Summary
汇编语言学习(五)
Jetpack Compose - remember, mutableStateOf, rememberSaveable
【ICDE 2022】阿里发布稀疏模型训练框架HybridBackend,单位成本下训练吞吐提升至5倍
汇编语言学习(九)
Es7.x使用RestHighLevelClient进行查询操作
C语言中的运算符(超全超详细)









