assemblyx86-16tasmdosbox

How can i show the 3 digit answer?

Note: I have Base 3 needed in addend and augend same as the answer need is base 3 how can i show ? I'am using notepad++ then tasm add.asm / tlink add / add. to execute the program. I'am new in dosbox so just want to learn how to show 3 digit answer in base 3.

``````.model small
.stack 100h
.data

Spc     db 0dh,0ah, " \$"                                                ;New Line
ErAd31  db 0dh,0ah, "Input only number to proceed [00-22 only]. \$"      ;Error Input Addition Addend and Augend

;Bases Calculation in Calculator
db 0dh,0ah, " "
BsA32   db 0dh,0ah, "Augend[00-22]:  \$"

SumA    db 0dh,0ah, "   Sum is    :  \$"                             ;Sum
AgA     db 0dh,0ah,0dh,0ah, "Add Again[Y/N]? : \$"                   ;Sum Again

;Calculation Logic
Dg11    db 0
Dg12    db 0

.code
main proc

mov ax,@data                    ;initialize ds
mov ds,ax

mov ah,09h
lea dx, Spc
int 21h

int 21h
mov ah,01h
int 21h                     ;1st Digit

cmp al,29h
cmp al,33h

sub al,30h
mov Dg11,al

mov ah,01h
int 21h                     ;2nd Digit

cmp al,29h
cmp al,33h

sub al,30h
mov Dg12,al

mov al, Dg11
mov bl,10h
mul bl

mov al,Dg12

mov ah,09h
lea dx, Spc
int 21h

int 21h

cmp al, 59h or 79h

mov ah,09h
lea dx, BsA32               ;Augend
int 21h
mov ah,01h
int 21h                     ;1st Digit

cmp al,29h
cmp al,33h

sub al,30h
mov Dg11,al

mov ah,01h
int 21h                     ;2nd Digit

cmp al,29h
cmp al,33h

sub al,30h
mov Dg12,al

mov al, Dg11
mov bl,10h
mul bl

mov al,Dg12

mov cx,bx

mov ah,09h
lea dx, SumA
int 21h
mov ah,02h
mov dl,ch
int 21h
mov dl,cl
int 21h

mov ah,09h
lea dx, Spc
int 21h

lea dx, AgA
int 21h
mov ah,01h
int 21h

cmp al, 59h or 79h
cmp al, 4Eh or 6Eh

mov ah,4Ch                      ;end here
int 21h

main endp
end main
``````

Needed Output:

``````Base 03 Addition

Augend[00-22]: 22
Sum is   :121

``````

Solution

• ``````cmp al, 29h       <================
cmp al, 33h
``````

and

``````mov al, Dg11
mov bl, 10h       <================
mul bl
``````

and

``````mov bl, NoAd1
mov cx, bx
``````

You seem to have trouble with the hexadecimal number system!

• To check the validity of the inputted digit, you should compare with 2Fh instead of 29h. You're forgetting that hex also uses A, B, C, D, E, and F as digits. The ASCII code directly below "0" is 2Fh (because the ASCII code of "0" is 30h).

• To convert your base-3 input, the multiplication should use 3, not 10h which is in effect equal to 16.

• I have no idea about what you think this `add cx, 3210h` could be doing.

how to show 3 digit answer in base 3.

Displaying a number in base 3 is no different from displaying a number in base 10. I copied next snippet of code from my answer at Displaying numbers with DOS. I changed `mov bx, 10` into `mov bx, 3` et voilĂ ...

``````    mov     al, NoAd1
mov     ah, 0
; Your number is in AX
mov     bx, 3          ; CONST
xor     cx, cx         ; Reset counter
.a: xor     dx, dx         ; Setup for division DX:AX / BX
div     bx             ; -> AX is Quotient, Remainder DX=[0,2]
push    dx             ; (1) Save remainder for now
inc     cx             ; One more digit
test    ax, ax         ; Is quotient zero?
jnz     .a             ; No, use as next dividend
.b: pop     dx             ; (1)
add     dl, "0"        ; Turn into character [0,2] -> ["0","2"]
mov     ah, 02h        ; DOS.DisplayCharacter
int     21h

``````

## It's cumbersome how you repeat or exit the program

``````  mov ah,01h
int 21h
cmp al, 59h or 79h
cmp al, 4Eh or 6Eh
``````
• This use of `or` does not offer a choice between UCase and LCase.
• Jumping to the top with a conditional jump forced you to introduce an intermediate label because the target was too far away.
• If the user presses none of the mentioned keys, you exit the program anyway. Then why bother to compare with "N" or "n"?

Better use:

``````AdAgain:
mov ah, 09h
lea dx, Spc
int 21h
lea dx, AgA    ; "Continue?"
int 21h

.z: mov ah, 01h
int 21h
or  al, 32     ; Make LCase
cmp al, "n"    ; 6Eh
(**) This `jmp` can jump all the way to the top. You no longer need the intermediate label Ad1.