汇编练习-3

虚拟机上运行的汇编


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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值