push and pop the stack is used to operate the two instructions.
push registers: a data register in the stack
pop register: a register stack receives a data
Here with some assembler code to learn about the stack operations (assembly language >> Wang Shuang environment with the set of environmental <<) with masm edit.
assume cs:codesg ;cs寄存器指向该程序的首地址
codesg segment
mov ax,1000H ;将1000H送入寄存器ax,相当于ax=1000H
mov ss,ax
mov sp,0010H
mov ax,001AH ;将ax,bx赋值
mov bx,001BH
push ax
push bx ;将ax,bx入栈
sub ax,ax ;sub为减法指令,相当于ax=ax-ax
sub bx,bx
pop ax //将栈顶的数据送入ax,pop也有mov指令类似的功能
pop bx
codesg ends
end
This code would space 10000H ~ 10000FH when this stack, the stack is empty in the initial state. Setting register ax, bx the value of the ax, bx data in the stack, and then the ax, bx is cleared back ax, bx original content from the stack.
ax, bx, sp, cs the register, ss of segment registers. Any time CPU (here represented by the register value and cs ip) from the CS * 16 + IP unit to execute instructions so disposed cs: codesg. At any time, ss * 16 + sp (ss here represents a value corresponding to the sp register) corresponding to the address pointing to the top element unit, the program which is provided ss = 1000H, instead of ss = 10000H.
The following look at the results of single-step debugging:
View the current contents of the registers r command, t is the one-step commands. Execution result of each step, the corresponding value of the register above, the following machine instructions corresponding to the next machine instruction is to be executed. Each execution of an instruction you will see a change in the corresponding register. Finally, a pop bx instruction due to the size of the picture reason, I did not cut it, so the final result row only perform pop ax, but not the results of the pop bx.
References: << >> Wang Shuang assembly language