【问题标题】:Assembly big numbers calculator大会大数字计算器
【发布时间】:2014-04-25 16:39:18
【问题描述】:

我得到了一项任务,要在 8086 汇编中制作一个计算器,该计算器将加、减、乘和除大十进制数。这些数字最多可以是 30 位数字。我使用了 3 个数组来存放这些数字(num1、num2、result)。我被加法困住了,因为每次我运行程序时,它都会显示结果数组是空的(它显示一个加号和 60 个零)你能告​​诉我的代码有什么问题吗?

ADDER:

    MOV     BP, offset num1
    MOV     SI, offset num2
    MOV     DI, offset result
    MOV     CL, byte ptr CS:[BP]
    MOV     CH, byte ptr CS:[SI]
    CMP     CL, CH
    JZ  addgood
    CMP     CL, '-'
    JNZ svers

   MOV     byte ptr CS:[BP], '+'                                       
   MOV     SI, offset num1
   MOV     BP, offset num2
   JMP SUBSTRACTOR
svers:

   CMP     CH, '-'
   MOV     byte ptr CS:[SI], '+'
   JMP SUBSTRACTOR

addgood:

lastdigit1:

    MOV     AL, byte ptr CS:[BP]
    CMP     AL, 127
    JZ      gotlastdigit1
    INC     BP
JMP lastdigit1
gotlastdigit1:

lastdigit2:
   MOV     AL, byte ptr CS:[SI]
   CMP     AL, 127
   JZ      gotlastdigit2
   INC     SI
   JMP lastdigit2

gotlastdigit2:

   MOV DI, offset result
   ADD DI, 60

initialaddition:

   CMP byte ptr CS:[BP], '+'
   JNZ notover1 
   JMP num1end
 notover1:
   CMP byte ptr CS:[BP], '-'
   JNZ notover2 
   JMP num1end
notover2:
   CMP byte ptr CS:[SI], '+'
   JNZ notover3 
   JMP num2end
notover3:
   CMP byte ptr CS:[SI], '-'
   JNZ notover4
   JMP num2end
notover4:
   MOV CH, byte ptr CS:[BP]
   MOV CS:[DI], CH
   MOV CH, byte ptr CS:[SI]    
   ADD CS:[DI], CH
   DEC BP
   DEC SI
   DEC DI
JMP initialaddition
afteriniadd:
   DEC DI
   MOV CL, 127
   MOV CS:[DI], CL
   MOV DI, offset result
   ADD DI, 60

truaddition:
   MOV CH, 0
   MOV CL, byte ptr CS:[DI]
   CMP CL, 10
   JNAE movealong
   CALL pisdod
movealong:    
   MOV CS:[DI], CL
   DEC DI
   MOV CL, byte ptr CS:[DI]
   CMP CL, 127
   JZ  isspecial    
   ADD CS:[DI], CH

 JMP truaddition
 isspecial:
   CMP CH, 0

   JZ  afteradd

   MOV CS:[DI], CH


afteradd:

   DEC DI
   MOV CS:[DI], 127
   MOV SI, offset num1
   MOV CL, CS:[SI]
   MOV DI, offset result
   CMP CL, '+'
   JZ  adplus
   MOV byte ptr CS:[DI], '-'
   JMP adminus
adplus:

   MOV byte ptr CS:[DI], '+'

adminus:

RET

子程序

num1end:
    MOV CL, '-'
    CMP byte ptr CS:[SI], CL
    JNZ noneed1 
    JMP afteriniadd
noneed1:
    MOV CL, '+'
    CMP byte ptr CS:[SI], CL
    JNZ noneed2
    JMP afteriniadd
noneed2:
    MOV CL, byte ptr CS:[SI]
    MOV byte ptr CS:[DI], CL
    DEC DI
    DEC SI
JMP num1end    

;......................................

num2end:
    MOV CL, '-'
    CMP byte ptr CS:[BP], CL
    JNZ noneed3
    JMP afteriniadd
noneed3:
    MOV CL, "+"
    CMP byte ptr CS:[BP], CL
    JNZ noneed4
    JMP afteriniadd
noneed4:
    MOV CL, byte ptr CS:[BP]
    MOV byte ptr CS:[DI], CL
    DEC DI
    DEC BP
JMP num2end

pisdod:
    CMP CL, 10
    JGE notyet 
    RET
notyet:
    SUB CL, 10
    INC CH
JMP pisdod

数组声明

num1    db  31 DUP(?), 127
num2    db  31 DUP(?), 127
result  db  61 DUP(?), 127

以 127 作为数字开始和结束的标记。

【问题讨论】:

    标签: arrays assembly calculator x86-16 addition


    【解决方案1】:

    我自己终于弄明白了。原来我不需要在afteradd: 部分中使用DEC DI。该命令导致标记被放置两次,一个接一个,这欺骗了应该打印结果的过程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-02
      • 2020-04-05
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多