注册 登录
编程论坛 汇编论坛

请求大神给点指导

wl1259472421 发布于 2013-06-08 19:34, 635 次点击
这是一个三位数的汇编程序,只需要16的寄存器,如何改写成八位数的汇编的程序。
assume cs:code
 data segment
 num db 0,0,0
 data ends

 code segment

 ;将百位数ax的值百位存到num[0],十位num[1],个位num[2]
 init:
 push ax
 push bx
 push cx
 push dx
 push bp

 mov bp,10
 lea bx,num
 add bx,2  

 mov cx,3
 init1:
 xor dx,dx
 div bp
 mov ds:[bx],dl
 dec bx
 loop init1   

 pop bp
 pop dx
 pop cx
 pop bx
 pop ax
 ret

 ;将num[]的三个数输出
print:

 push ax
 push cx
 push dx

 lea bx,num
 mov cx,3
 print1:
 mov dl,ds:[bx]
 add dl,30h
 mov ah,2
 int 21h
 inc bx
 loop print1

 mov ah,2
 mov dx,10
 int 21h

 pop dx
 pop cx
 pop ax

 ret

 ;将num[3]的每个数的3次方相加保存到ax
 calc:

 push bx
 push cx
 push dx  
 push si
 push bp

 xor si,si
 mov cx,3  
 lea bx,num
 calc1:
 mov al,ds:[bx]  
 mov ah,0
 mov bp,ax
 mul bp
 mul bp
 add si,ax   
 inc bx
 loop calc1
 mov ax,si   
   
 pop bp
 pop si
 pop dx
 pop cx
 pop bx

 ret

 start:
 mov ax,data
 mov ds,ax

 mov cx,99
 s:  
 inc cx
 cmp cx,999
 ja exit

 mov ax,cx
 call init

 call calc
 cmp ax,cx   
 jne s   

 call print
 jmp s

 exit:
 mov ah,4ch
 int 21h
 code ends
 end start
2 回复
#2
hu9jj2013-06-09 07:10
试试看:
assume cs:code
data segment
num db 0,0,0,0,0,0,0,0
data ends

code segment

;将百位数ax的值百位存到num[0],十位num[1],个位num[2]
init:
push ax
push bx
push cx
push dx
push bp

mov bp,10
lea bx,num
add bx,2  

mov cx,8
init1:
xor dx,dx
div bp
mov ds:[bx],dl
dec bx
loop init1   

pop bp
pop dx
pop cx
pop bx
pop ax
ret

;将num[]的三个数输出
print:

push ax
push cx
push dx

lea bx,num
mov cx,8
print1:
mov dl,ds:[bx]
add dl,30h
mov ah,2
int 21h
inc bx
loop print1

mov ah,2
mov dx,10
int 21h

pop dx
pop cx
pop ax

ret

;将num[3]的每个数的3次方相加保存到ax
calc:

push bx
push cx
push dx  
push si
push bp

xor si,si
mov cx,3  
lea bx,num
calc1:
mov al,ds:[bx]  
mov ah,0
mov bp,ax
mul bp
mul bp
add si,ax   
inc bx
loop calc1
mov ax,si   
   
pop bp
pop si
pop dx
pop cx
pop bx

ret

start:
mov ax,data
mov ds,ax

mov cx,99
s:  
inc cx
cmp cx,999
ja exit

mov ax,cx
call init

call calc
cmp ax,cx   
jne s   

call print
jmp s

exit:
mov ah,4ch
int 21h
code ends
end start
#3
wl12594724212013-06-10 20:15
回复 2楼 hu9jj
上面那种该法不行的,四位的可以改。但是超过5位的话要使用32位的寄存器。请你花点时间帮我看看吧
1