5.6 十进制和十六进制转换,lea指令,写注释
1. 将十进制100转换成十六进制64
assume cs:codesg,ds:data,ss:stack
data segmeNT
str db '00000100','$'
data ends
stack segment
db 10 dup(0)
stack ends
codesg SEgment
start:
mov ax,data
mov ds,ax
mov bx,0
mov cx,8
mov ax,0
s:
mov dx,ax
shl ax,1
shl ax,1
shl ax,1
shl dx,1
add ax,dx
;乘10
add al,str[bx]
adc ah,0
sub ax,30h
inc bx
loop s
mov ah,4ch
int 21h
codesg ends
end start
comment*
string str = "00000100"
int res = 0
for (int i = 0; i < 8; i++)
res = res * 10 + str[i] - '0';
return res
*comment
![image.png](https://i-blog.csdnimg.cn/blog_migrate/70cf68960e2a9f0976b59cbf57cf4f61.png)
2. 将10进制12345转换为16进制3039并且输出
2.1 将10进制12345转换为16进制并存到内存当中
assume cs:codesg,ds:data,ss:stack
data segmeNT
str db '00012345','$'
res db '0000','$'
data ends
stack segment
db 100 dup(0)
stack ends
codesg SEgment
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,10
mov si,4
mov bx,0
mov cx,8
mov ax,0
s:
mov dx,ax
shl ax,1
shl ax,1
shl ax,1
shl dx,1
add ax,dx
;乘10
add al,str[bx]
adc ah,0
sub ax,30h
inc bx
loop s
;ax = 3039
mov cx,4
l:
mov dx,ax
and dx,0fh
add dx,30h
cmp dx,40h
jb s1
add dx,7h
;求出3039的ASCII码,push
s1:
dec si
mov ds:res[si],dl
shr ax,1
shr ax,1
shr ax,1
shr ax,1
loop l
mov ah,4ch
int 21h
codesg ends
end start
comment*
if (res = 0) ans++;
cmp ax,bx
jne s1
inc dx
s1:
if (x == 1) res = 10
else res = 20
mov res,10
cmp x,1
je s1
add res,10
s1:
*comment
![image.png](https://i-blog.csdnimg.cn/blog_migrate/06e519e7d199f86d68b5851c66bef7fd.png)
2.2 将10进制12345转换为16进制并直接输出
;mov dx,offset res
lea dx,res
mov ah,9
int 21h
![image.png](https://i-blog.csdnimg.cn/blog_migrate/75d6d53a88e12921d9656665ae6e1241.png)