汇编将32位转换为10进制输出

本文章由孙旭编写,未经允许,不要传播啦
stack     segment
	db 1024 dup(?)
stack     ends

data      segment
	x dw ?
	y dw ?
	zl dw ?
	zh dw ?
	tag db 1
data      ends

code      segment
	assume cs:code,ds:data,ss:stack
	
start:  
          mov ax,data
          mov ds,ax
          sub sp,4
          call read
          mov x,ax
          push ax
          call read
          mov y,ax
          push ax
          call Calulate;求结果
          call Print
          mov ah,4ch
          int 21h
          
          
          ;运算子程序
          Calulate proc
          push bp
          mov bp,sp
          mov ax,[bp+6]
          mov bx,[bp+4]
          imul bx
          mov bx,ax
          mov cx,dx
          mov ax,[bp+6]
          cwd
          add bx,ax
          adc cx,dx
          mov ax,[bp+4]
          cwd
          sub bx,ax
          sbb cx,dx
          mov word ptr [bp+8],bx
          mov word ptr [bp+10],cx
          mov ax,[bp+8]
          mov zl,ax
          mov ax,[bp+10]
          mov zh,ax
          
          pop bp
          ret 4
          Calulate endp
          
          ;转换为十进制输出
          Print proc
          xor si,si
          xor ax,ax
          cwd
          cmp cx,0
          
          jae next1
          and cx,7fffh
          mov tag,0
  
next1:    cmp cx,0
          ja next2
          cmp bx,10
          jae next2
          inc si
          push bx
          mov bx,ax
          mov cx,dx
          xor ax,ax
          cwd
          cmp cx,0
          jg next3
          cmp bx,10
          jae next3
          inc si
          push bx
          jmp done1
next2:    add ax,1
          adc dx,0
          sub bx,10
          sbb cx,0
next3:    jmp next1

done1:    mov al,tag
          cmp al, 1
          je next4
          mov dl,'-'
          mov ah,02h
          int 21h
next4:    mov cx,si
again:    pop dx
          or dl,30h
          mov ah,02h
          int 21h
          loop again
          Print endp
          
          
          ;输入十进制数
          read proc
          push bx
          push cx
          push dx
          xor bx,bx
          xor cx,cx
          mov ah,1
          int 21h
          cmp al,'+'
          jz read1
          cmp al,'-'
          jnz read2
          mov cx,-1
read1:    mov ah,1
          int 21h
read2:    cmp al,'0'
          jb read3
          cmp al,'9'
          ja read3
          sub al,30h
          
          shl bx,1
          mov dx,bx
          shl bx,1
          shl bx,1
          add bx,dx
          
          mov ah,0
          add bx,ax
          jmp read1
read3:    cmp cx,0
          jz read4
          neg bx
read4:    mov ax,bx
          pop dx
          pop cx
          pop bx
          ret
          read endp
          
code      ends
          end start



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值