2014-09-19 2 views
3

내 코드의 일부는 두 정수의 합, 차액, 곱 및 지수를 가져와 표시해야합니다. 그것은 합계, 차이 및 제품에 대해 잘 작동합니다. 그러나 몫에 관해서는 아무 것도 표시하지 않습니다. 누구나 이유를 설명해 주시고 해결 방법이 있다면 알려주십시오. 미리 감사드립니다. 예를 들어, 어떻게 I는 두 번째로 제 번호 3과 같은 입력 (9),이 경우, 어떤두 정수의 몫이 어셈블리에 표시되지 않습니다.

printAns proc 
     xor cx, cx 
     xor dx, dx 
     xor bx, bx 
     mov bx, 10 
     loop1: 
      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 loop1   ;jumps if ax is not zero 

     loop2: 
      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 loop2   ;loops till cx equals zero 
     xor ax, ax 
     xor bx, bx 
    ret 
printAns endp 

: enter image description here

+2

나누기 전에 'dx'를 잊어 버렸습니다. – Jester

+0

오, 이런, 정말 고마워! 나는 그것이 그렇게 단순하다는 것을 깨닫지 못했다. – user2758902

+1

질문에 대해 +1을 클릭했습니다. 귀하가 충분히 이해할 수 있도록 댓글을 달았 기 때문입니다. 여기있는 사람들은 거의 없다. –

답변

0

분할 미스

printString result1 
    plus: 
     mov ax, firstInteger 
     mov bx, secondInteger 
     add ax, bx 

     call printAns 

    call printNewLine 
; --------------------------------------------------------------------------- 
    printString result2 
    minus: 
     mov ax, firstInteger 
     mov bx, secondInteger 
     sub ax, bx 

     call printAns 

    call printNewLine 
; --------------------------------------------------------------------------- 
    printString result3 
    multiply: 
     mov ax, firstInteger 
     mov bx, secondInteger 
     mul bx 

     call printAns 

    call printNewLine 
; --------------------------------------------------------------------------- 
    printString result4 
    divide: 
     mov ax, firstInteger 
     mov bx, secondInteger 
     div bx 

     call printAns 

    call printNewLine 

printAns은 다음과 같다 워드 분할은 항상 지정된 피연산자에 의해 DX : AX를 나눕니다.

printString result4 
divide: 
mov ax, firstInteger 
xor dx, dx 
div secondInteger 
call printAns 
call printNewLine 
관련 문제