0
DATASEG
num1 db ?
num2 db ?
answer db "Enter a multiply equation$"
sum db " $"

CODESEG 
start:
    mov ax, @data
    mov ds, ax

; display question
xor ax , ax
mov dx , offset answer
mov ah , 9
int 21h
; input num1
mov ah,1h
int 21h
sub al , '0'
mov [num1] , al
xor ax , ax

;print *
mov dl , '*'
mov ah , 2
int 21h

xor ax , ax
; input num2
mov ah,1h
int 21h
sub al , '0'
mov [num2] , al
xor ax,ax
; num1 * num2
mov al , [num1] 
mov bl , [num2] 

mul bl 
add al , '0'
mov [sum] , al
;print =
mov dl , '='
mov ah ,2
int 21h
; print sum (num1 * num2)
mov dx , offset sum
mov ah ,9
int 21h

Program supposed to get 2 same numbers multiply and return the answer the challenge is the numbers having to be 4-9 so the answer is 2 digits Ive gotten to the point where it prints the number but the hexa value

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • After your `mul bl` instruction, you write `add al, '0'`, but that would assume the result of `mul` (the value in `ax`) is a single decimal digit. So your result is not going to be correct even for the hexadecimal output case for large enough products. After your `mul` you need to break the `ax` product into decimal digits. You can do so by dividing by 10 and looking at the quotient and remainder. – lurker Dec 18 '21 at 13:57
  • @PeterCordes the title of this question is a little ambiguous, but the OP wants to print the result in decimal instead of hex. – lurker Dec 18 '21 at 14:31
  • 2
    @lurker: Oh, I see. Pretty sure this doesn't actually correctly print a hex digit, since it's just adding `'0'` to an 8-bit result. That will be an alphabetic character for some numeric results, but not the *correct* hex digit. But anyway, that makes it a duplicate of [Displaying numbers with DOS](https://stackoverflow.com/q/45904075). I guess I'll leave the other duplicates there to answer the wrong claim that this was producing a hexadecimal value rather than some wrong ASCII character. – Peter Cordes Dec 18 '21 at 14:56
  • @PeterCordes yep, you're right. I had commented on that as well (that it won't even do hex correctly if the product is greater than 0xF). – lurker Dec 18 '21 at 14:58
  • 2
    @lurker: It's wrong if the product is greater than 0x9. In ASCII `'0' + 10` is `';'` not `'A'`, inconvenient for int->hex but it makes a lot of sense to lay out the code-points that way for other reasons, e.g. aligning the alphabets within % 32 regions. ([What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](https://stackoverflow.com/a/54585515)) – Peter Cordes Dec 18 '21 at 15:03
  • @PeterCordes ah of course hehe. Sheesh, I need more coffee. – lurker Dec 18 '21 at 15:04

0 Answers0