在8086大会32位计算器 [英] 32 bit Calculator in 8086 Assembly

查看:212
本文介绍了在8086大会32位计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算器32位

有人可以帮助我在我的MASM32的32位计算器。我认为加和减是确定的,但我不能打印十进制数;

0002FFFF - 10005 = 1fffa

在记忆:0001 0FFFA

印刷:165530十进制

  DATA_HERE段    MULT1 DW 0002H
          DW 0FFFFH
    mult2 DW 0001H
          DW 0005H
    答DW 0,0DATA_HERE ENDSSTACK_HERE段STACK
    DW 40 DUP(0)
STACK_HERE ENDScode_HERE段
    承担CS:code_HERE,DS:DATA_HERE,SS:STACK_HEREINICIO:
MOV AX,DATA_HERE
MOV DS,AX加:MOV AX,MULT1 + 2;采取NUM1的低16位;采取
ADD AX,mult2 + 2; AX = AX + NUM2的低16位
MOV ANS + 2,AX;在存储较低答16位结果MOV AX,MULT1;采取NUM1在AX中的高16位;
ADC AX,mult2; AX = AX + NUM2 + CF(带进位加法)
答MOV,AX;在存放高ANS 16位结果
减去:
MOV AX,MULT1 + 2;采取NUM1在AX中的低16位;
SUB AX,mult2 + 2; AX = AX - NUM2的低16位
MOV ANS + 2,AX;在存储较低答16位结果MOV AX,MULT1;采取NUM1在AX中的高16位;
SUB AX,mult2; AX = AX - NUM2
答MOV,AX;在存放高ANS 16位结果异或SI,SI
MOV SI,0CICLO:
   MOV AX,ANS [SI];
   来电显示;打印AX
   加SI,2CMP SI,2
JLE CICLOMOV AX,4C00h
INT 21H显示PROC
  ;推CX
  ;程序开始
  MOV BX,10;初始化除数
  ; MOV DX,0000H;清除DX
  MOV CX,0000H;清除CX
      ;分裂过程从这里开始
.Dloop1:
   MOV DX,0000H;跳时清除DX
   DIV BX;由BX AX除以
   PUSH DX;推DX(余)堆栈
   INC CX;增量计数器来跟踪的位数
   CMP AX,0;检查是否还有东西在AX分
   JNE .Dloop1;如果跳转AX不为零.Dloop2:POP DX;从流行栈DX
   ADD DX,30H,转换为它的等效ASCII
   MOV AH,02H
   INT 21H;调用DOS显示字符
LOOP .Dloop2;循环直至CX等于零   ;弹出CX
   RET;返回控制
显示ENDPcode_HERE ENDS
END INICIO


解决方案

您先打印低16位为小数FFFA - > 65530和1从第二个字。

1 65530.

如果你有一个32位处理器可以用EAX / EDX寄存器执行你除法。

如果没有它是比较复杂的。然后,你必须模拟32位divission。这是没有乐趣;-)。

下面有一个提示: http://en.wikipedia.org/wiki/Division_algorithm (是的,你必须处理位)

如果你写一个C PROGRAMM是除以10L长值,编译为您的处理器(16位)和dissasemble输出的话,你可以看到他们是如何做到这一点。这只是一个想法。我还没有尝试过自己。你必须ASURE你的长期价值足够大,以便编译器没有机会来优化。 ; - )

CALCULATOR 32 Bit

Can someone help me with my 32 bit calculator in MASM32. i think the adding and subtracting is OK but i cant print the number in decimal;

0002FFFF - 10005 = 1fffa

In MEMORY :0001 0FFFA

PRINTING: 165530 in decimal

DATA_HERE     SEGMENT       

    mult1 dw 0002H
          dw 0FFFFH
    mult2 dw 0001H
          dw 0005H
    ans   dw 0,0

DATA_HERE    ENDS

STACK_HERE     SEGMENT STACK
    DW 40 DUP(0)
STACK_HERE    ENDS

CODE_HERE    SEGMENT
    ASSUME CS:CODE_HERE, DS:DATA_HERE, SS: STACK_HERE

INICIO:
MOV AX,DATA_HERE
MOV DS,AX   

ADD:

MOV AX,mult1+2 ; take lower 16-bit of NUM1; take 
ADD AX,mult2+2 ; AX = AX + lower 16-bit of NUM2
MOV ans+2,AX ; Store lower 16-bit result at ans

MOV AX,mult1 ; take higher 16-bit of NUM1 in AX; 
ADC AX,mult2 ; AX = AX + NUM2 + CF (add with carry)
MOV ans,AX ; Store higher 16-bit result at ans


SUBTRACT:


MOV AX,mult1+2 ; take lower 16-bit of NUM1 in AX ; 
SUB AX,mult2+2 ; AX = AX - lower 16-bit of NUM2
MOV ans+2,AX ; Store lower 16-bit result at ans

MOV AX,mult1 ; take higher 16-bit of NUM1 in AX; 
SUB AX,mult2 ; AX = AX - NUM2
MOV ans,AX ; Store higher 16-bit result at ans

xor si,si
mov si,0   

ciclo:        
   mov AX, ans[si];          
   call display ; print AX
   add si, 2

cmp si, 2
JLE ciclo

mov ax,4C00h
int 21h        

display   proc  
  ;push CX     
  ;Beginning of procedure
  MOV BX, 10     ;Initializes divisor
  ;MOV DX, 0000H    ;Clears DX
  MOV CX, 0000H    ;Clears CX
      ;Splitting process starts here
.Dloop1:  
   MOV DX, 0000H    ;Clears DX during jump
   DIV BX      ;Divides AX by BX
   PUSH DX     ;Pushes DX(remainder) to stack
   INC CX      ;Increments counter to track the number of digits
   CMP AX, 0     ;Checks if there is still something in AX to divide
   JNE .Dloop1     ;Jumps if AX is not zero

.Dloop2:  POP DX      ;Pops from stack to DX
   ADD DX, 30H     ;Converts to it's ASCII equivalent
   MOV AH, 02H     
   INT 21H      ;calls DOS to display character
LOOP .Dloop2    ;Loops till CX equals zero

   ;pop CX
   RET       ;returns control
display  ENDP



CODE_HERE    ENDS
END INICIO

解决方案

You first print the lower 16 Bit as a decimal FFFA -> 65530 and the 1 from the second word.

1 65530.

If you have a 32 Bit Processor you can perform you division with EAX/EDX registers.

If not it is more complicated. Then you have to simulate a 32 Bit divission. That's no fun ;-).

Here's a hint: http://en.wikipedia.org/wiki/Division_algorithm (yes you must handle bits)

If you write a C programm that divides a long value by 10L, compile it for your processor (16 Bit) and dissasemble the output then, you can see how they do it. It's just an idea. I have not tried it myself. You must asure that your long value is big enough so that the compiler has no chance to optimize. ;-)

这篇关于在8086大会32位计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆