|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
datasg segment
ADDRESS1 db 16, ?, 16 dup (?)
INFO1 db 'InputAddress:$'
INFO2 db 0dh, 0ah, 'Error', 0dh, 0ah, '$'
datasg ends
;==============================================================================
codesg segment
assume cs:codesg, ds:datasg
start: mov ax, seg INFO1
mov ds, ax
call GetAddress
ok: xor al, al
mov ah, 4ch
int 21h
;名称:GetAddress
;功能:接受用户输入的地址字符串将其转换成逻辑地址
;入口参数:无
;出口参数:es:bx = 转换后的逻辑地址
GetAddress proc near
push ax
push cx
push dx
push si
push bp
mov bp, sp
sub sp, 2
sub sp, 2
mov word ptr [bp-2], 0
mov word ptr [bp-4], 0 ;记录":"前面字符的长度
;提示输入地址
mov dx, offset INFO1
mov ah, 9
int 21h
;接受输入保存到约定的缓冲区ADDRESS1中
mov dx, offset ADDRESS1
mov ah, 0ah
int 21h
;判断输入是否合法
mov al, ADDRESS1+1
cmp al, 9
jbe jc_next1 ;跳转到检查2
error1: mov dx, offset INFO2
mov ah, 9
int 21h
jmp short ga_ok ;结束
jc_next1: mov si, offset ADDRESS1 + 1
xor ch, ch
mov cl, ADDRESS1+1
jc_next2: inc si
mov al, [si]
cmp al, ':'
jnz jc_next4
jc_next3: inc word ptr [bp-2]
cmp word ptr [bp-2], 1
ja error1
cmp si, offset ADDRESS1 + 6
ja error1
cmp cl, 1
jz error1
cmp cl, ADDRESS1 + 1
jz error1
jmp short jc_next6
jc_next4: cmp al, 30h
jb error1
cmp al, 39h
ja jc_next5
jmp short jc_next6
jc_next5: or al, 20h ;转换为小写字母
cmp al, 61h
jb error1 ;不合法
cmp al, 66h
ja error1 ;不合法
jc_next6: cmp word ptr [bp-2], 0
jnz jc_next7
inc word ptr [bp-4]
jc_next7: loop jc_next2
ga_next1: mov ax, seg ADDRESS1
push ax
mov ax, offset ADDRESS1 + 2
push ax
mov ax, [bp-4]
push ax
call AToB
mov es, ax
mov ax, seg ADDRESS1
push ax
mov ax, offset ADDRESS1 + 3
add ax, word ptr [bp-4]
push ax
xor ah, ah
mov al, ADDRESS1 + 1
dec ax
sub ax, [bp-4]
push ax
call AToB
mov bx, ax
ga_ok: mov sp, bp
pop bp
pop si
pop dx
pop cx
pop ax
ret
GetAddress endp
;名称:AToB
;功能:将16进制ASCII码转换成2进制数
;入口参数:字符串段地址、偏移地址、字符串长度
;出口参数:(ax) = Bin
AToB proc near
push bx
push cx
push dx
push es
push bp
mov bp, sp
sub sp, 2
mov word ptr [bp-2], 16
mov cx, [bp+12]
mov bx, [bp+14]
mov es, [bp+16]
xor ax, ax
atb_next1: mov dl, es:[bx]
sub dl, 30h
cmp dl, 9
jbe atb_next2
sub dl, 7
atb_next2: inc bx
add al, dl
adc ah, 0
cmp cx, 1
jz atb_next3
xor dx, dx
mul word ptr [bp-2]
loop atb_next1
atb_next3: mov sp, bp
pop bp
pop es
pop dx
pop cx
pop bx
ret 6
AToB endp
codesg ends
;==============================================================================
end start
|
|