;这是一个显示16位模式下PUSH指令操作情况的程序
;程序将显示栈中压入不同长度立即数后,栈指针的变化情况
;PUSHexecute.asm
;by 鱼C论坛 ID:兰陵月
;2017年11月19日
;----------------------程序开始----------------------
jmp near start
;----------------------------------------------------
;数据定义区
info_begin db 'PUSH Operation: ',0
info_num db 'Number: ',0
info_size db 'Size: ',0
num_one db '0x55. ',0
info_imm db 'IMME',0
info_byte db 'BYTE',0
;info_word db 'WORD',0
;info_dword db 'DWORD',0
seg_add db ' Current SS: ',0
eff_add db ' Current SP: ',0
hex_sign db '0x',0
num1_push db "Push 0x55. SP: ",0
num2_push db "Push byte 0x55. SP: ",0
num3_push db "Push word 0x55. SP: ",0
num4_push db "push dword 0x55. SP: ",0
hex_buff db 0,0,0,0 ;存放十六进制个位数字的ASCII码值
;----------------------------------------------------
;显示带'0'结束标志信息过程
;入口参数,寄存器bx-存放要显示信息的首地址
;入口参数,寄存器ah-要显示的字符的颜色。
show_info:
mov al,[bx]
cmp al,0
jz show_end
mov [es:di],al
inc di
mov [es:di],ah
inc di
inc bx
jmp show_info
show_end:
ret
;显示信息过程结束
;----------------------------------------------------
;----------------------------------------------------
;转换到十六进制数字,并显示
;入口参数,寄存器AX-要显示的寄存器的内容
;入口参数,hex_buff,存放每个位数值的缓冲区首地址
to_Hex:
mov si,hex_buff
mov cx,4
mov bx,16
@lp1:
xor dx,dx
div bx
cmp dl,9
jbe @num
add dl,0x07
@num: add dl,0x30
mov [si],dl
inc si
loop @lp1
dec si
mov cx,4
@lp2:
mov bl,[si]
mov [es:di],bl
inc di
mov bl,0x04
mov [es:di],bl
inc di
dec si
loop @lp2
ret
;----------------------------------------------------
;显示相关信息
start: mov ax,0x7c0
mov ds,ax
mov ax,0xb800
mov es,ax
xor al,al
mov di,160
mov ah,0x07
mov bx,info_begin
call show_info
mov ah,0x04
mov bx,info_imm
call show_info
mov ah,0x07
mov di,480
mov bx,info_num
call show_info
mov ah,0x04
mov bx,num_one
call show_info
mov ah,0x07
;mov di,800
mov bx,info_size
call show_info
mov ah,0x04
mov bx,info_byte
call show_info
;显示相关信息结束。
;----------------------------------------------------
;----------------------------------------------------
;压栈操作
mov ax,0x00
mov ss,ax
mov sp,0x7fff
mov ah,0x07
mov di,800
mov bx,seg_add
call show_info
;mov ah,0x04
;mov bx,hex_sign
;call show_info
mov ax,ss
call to_Hex
;--------------------------
;显示未开始push操作前SP值
mov ah,0x07
mov di,960
mov bx,eff_add
call show_info
;mov ah,0x04
;mov bx,hex_sign
;call show_info
mov ax,sp
call to_Hex
;--------------------------
;push 0x55(无前缀)
mov ah,0x07
mov di,1120
mov bx,num1_push
call show_info
push 0x55
mov ax,sp
call to_Hex
;--------------------------
;push byte 0x55(有byte前缀)
mov ah,0x07
mov di,1280
mov bx,num2_push
call show_info
push byte 0x55
mov ax,sp
call to_Hex
;--------------------------
;push word 0x55(有word前缀)
mov ah,0x07
mov di,1440
mov bx,num3_push
call show_info
push word 0x55
mov ax,sp
call to_Hex
;--------------------------
;push dword 0x55(有dword前缀)
mov ah,0x07
mov di,1600
mov bx,num4_push
call show_info
push dword 0x55
mov ax,sp
call to_Hex
jmp $
times 510-($-$) db 0
db 0x55,0xaa