Posted on 2014-12-19 22:53
jacky_zz 阅读(415)
评论(0) 编辑 收藏 引用 所属分类:
ASM
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc\0_com_template.txt
org 100h
start:
jmp main
stack:
db 256 dup(0)
code_len:
dw 0
; add your code here
main:
mov ax, cs
mov ds, ax
mov ss, ax
mov sp, stack+256
mov ax, end
mov bx, main
sub ax, bx
mov bx, 2
div bx
cmp dx, 0
je next_step
inc ax
next_step:
mov bx, code_len
mov [bx], ax
mov bx, main
push ax
push bx
push cs
call dump_memory
pop ax
pop bx
pop ax
hlt
dump_memory:
push bp
push ax
push bx
push cx
push dx
push ds
mov bp, sp
mov ax, [bp+14]
mov bx, [bp+16]
mov cx, [bp+18]
xor dx, dx
mov ds, ax
rotate_memory:
mov ax, ds:[bx]
push ax
call write_hex
pop ax
add bx, 2
loop rotate_memory
pop ax
mov ds, ax
pop dx
pop cx
pop bx
pop ax
pop bp
ret
write_hex:
push bp
push ax
push bx
push cx
push dx
mov bp, sp
mov bx, [bp+12]
xor ax, ax
xor cx, cx
mov ch, 4
rotate:
mov cl, 4
rol bx, cl
mov al, bl
and al, 0x0f
add al, 0x30
cmp al, 0x3a
jl printit
add al, 0x07
printit:
mov dl, al
push dx
call write_char
pop dx
dec ch
jnz rotate
mov dx, 0x0000
push dx
call write_char
pop dx
pop dx
pop cx
pop bx
pop ax
pop bp
ret
write_char:
push bp
push ax
push dx
mov bp, sp
mov ah, 0x02
mov dx, [bp+8]
int 0x21
pop dx
pop ax
pop bp
ret
end: db 0x55,0xaa