虚拟机上运行的汇编
org 07c00h
buf: db "000011111",0
start:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,8000h
mov di,buf
mov ax,1246h
call print_hex
mov di,buf
mov dx,0
call print
jmp $
;**************************************************************
; Desc: print string and the end valid ZERO
; Input: DI(string address)
;
DX(cursor position)
print:
push bx
push cx
call strlen
mov cx,ax
mov bp,di
mov bx,00001001B ; default blue color
mov ax,1301h
int 10h
pop cx
pop bx
ret
;**************************************************************
; Calulate the lenght of a string, the end value is ZERO as C/C++ language
; Input: DI(string address)
; Output: AX(string length)
strlen:
push bx
push di
mov ax,0
mov bl,0
gsl_begin:
cs cmp [di],bl
je gsl_over
inc ax
inc di
jmp gsl_begin
gsl_over:
pop di
pop bx
ret
;**************************************************************
; Desc: convert the AL to a hex character
;
hex_table: db "0123456789ABCDEF"
tohex:
push bx
mov bx,hex_table
xlat
pop bx
ret
;***************************************************************
; Desc: print register AX whit hex, the DI is the address to fill
;
print_hex:
push bx
push cx
push di
add di,4
mov bx,ax
mov cx,4
phbegin:
mov ax,bx
and ax,000fh
call tohex
mov [di],al
shr bx,4
dec di
loop phbegin
pop di
pop cx
pop bx
ret
|