Hi guys..i've been cracking my head for the past few days, i can't seem to print out the result of my multiplication..I'm using MASM615..Can anyone give me some pointers ?

.MODEL MEDIUM
.STACK 
.DATA 

;==================================
ONE DW 04DEH ; First signed number A = (-79H) = FF87H (2'Compliment form)
TWO DW 096CH ; Second signed number B = (-7CH) = FF84H (2'Compliment form)
THREE DW ? ; Variable C to store result
FOUR DW ?

MSGTWO db "enter first number:$"
MSGTRI db "enter second number:$"
;MSGFOUR db "Answer  : $"
;MSGFIVE db  "thank you for using the calculator! press any ;key...$"
;ERROR db  "wrong operator!$"
;==================================
PARALIST LABEL BYTE
MAX	 DB 	6
ACT 	 DB	?
PARADATA DB 	6 DUP (' ')

PARALIST2 LABEL BYTE
MAX2	 DB 	6
ACT2 	 DB	?
PARADATA2 DB 	6 DUP (' ')

;===================================


.CODE


MAIN PROC

MOV AX,@DATA
MOV DS,AX
MOV SI,0000H ; Initialize SI to 0000H

;Prompt For Input

LEA DX,MSGTWO
MOV AH,09H
INT 21H

MOV AH,0AH
LEA DX,PARALIST
INT 21H

;New Line

MOV AH,02H
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H

;Prompt For Input2
LEA DX,MSGTRI
MOV AH,09H
INT 21H

MOV AH,0AH
LEA DX,PARALIST2
INT 21H

;New Line

MOV AH,02H
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H

;mov $ sign
MOV BL,ACT
MOV BH,00
MOV PARADATA[BX],'$'

;mov $ sign
MOV BL,ACT2
MOV BH,00
MOV PARADATA2[BX],'$'

; Perform Multiplication

LEA AX,PARADATA ;Take first number A in AX register
LEA CX,PARADATA2 ;Take second number B in CX register
MUL CX ; Performs unsigned Multiplication DX:AX = AX × CX

MOV SI,DX

MOV FOUR,SI ; Store higher 16-bit result

MOV AH,09H
MOV DX,FOUR
INT 21H

MOV AH,02H
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H

MOV SI,AX

MOV THREE,SI ; Store lower 16-bit result

MOV AH,09H
MOV DX,THREE
INT 21H

MOV AX,4c00H
INT 21H

MAIN ENDP
END MAIN

The part in red color is probably where i've gone wrong..been reading lotsa books but i don't get it..=/

Dani AI

Generated

The immediate problems in the posted program are two-fold: you are multiplying addresses/strings instead of numeric values, and you are trying to print a raw word with DOS print (INT 21h/AH=09), which expects DS:DX to point at a $-terminated string. Loading the input buffer address into a register and doing MUL will multiply the address, not the number the user typed. Also the DOS buffered-read (function 0Ah) stores the count at offset+1 and the characters at offset+2 — you must place a '$' after the characters if you plan to call AH=09 on that buffer.

Concrete fix checklist

  • Extract the typed characters (buffer+2, length = buffer+1).
  • Convert the ASCII hex string to a numeric 16-bit value: for each character map '0'..'9','A'..'F','a'..'f' to 0..15, then acc = acc*16 + nibble. Handle an optional leading '-' if you want signed input. Put the result in AX (or AX:DX if you need 32-bit).
  • Multiply the numeric words with IMUL (signed) or MUL (unsigned). The 16-bit product is returned in DX:AX.
  • Convert DX:AX to an ASCII hex (or decimal) string: convert the high word (DX) and low word (AX) each into four hex characters (nibble -> '0'..'9' or 'A'..'F'), append a '$', then point DX at that buffer and call AH=09.

Small helper example (nibble -> ASCII)

; AL = 0..15 -> returns ASCII in AL
cmp al, 10
jb .digit
add al, 'A' - 10
jmp .done
.digit:
add al, '0'
.done:

Use small, reusable procedures: e.g. parse_hex PROC (input: DS:SI,length in CL -> output: AX = value) and word_to_hex PROC (input: AX -> writes 4 ASCII hex chars to buffer). Preserve registers with PUSH/POP around calls. Test each routine independently (convert a hard-coded string, then multiply fixed values) before wiring the full input/read/print flow.

is correct to suggest a conversion routine; follow that by writing a parse_hex and a print_hex helper. , start by printing the converted numeric to confirm parsing works before multiplying. : learning these small helpers is safer than asking for a one-shot "complete code" — you will understand and be able to adapt the routines.

Recommended Answers

All 4 Replies

The problem is that you are trying to multiply strings, which you cannot do.

Remember, the string '12' is different from the number 12.

So, you must first convert the PARADATA strings into numbers, multiply them together, then convert the resulting number back to a string, which you can print.


Since you seem to have a pretty good grasp of things, might I recommend you use some subroutines? (You don't need to, but it'll make things nicer.)

I haven't read anything past the attempt to multiply strings...
Hope this helps.

Subroutines ? what are those ?

By that does it means that i have to use MOV offset ? i'm not really sure

The difference is how data is represented in memory.

str1 db 52, 50
str2 db '42'

The strings str1 and str2 are identical. Both contain the two-character ASCII string "42".
However, the number 42 is stored as just that:

num db 42

Notice how the only difference is how we think about it. We could say that str2 is really just an array of two numbers: 52 and 50. Or a single WORD-sized number: 12852. Or a string. Once we decide what it is we must use it correctly.

Since the user input is an ASCII string, we must change it into its proper numeric representation.

The ASCII digits and their numerical values are:

ASCII
char  '0'  '1'  '2'  '3'  '4'  '5'  '6'  '7'  '8'  '9'
value 48   49   50   51   52   53   54   55   56   57

To convert the representation (in ASCII) to its numerical value, we must do a little math:

(as numbers)
52, 50 - 48, 48 = 4, 2
(as characters)
'4', '2' - '0', '0' = 4, 2

Now we just need to change the sequence 4, 2 into a single number:
4 * 10 = 40
40 + 2 = 42

This should be enough to get you started. I recommend that you do it in a procedure:

str_to_int PROC NEAR
        ; this proc converts the $-terminated string at DX into a number
        ; the number is put in AX

        ; (you must write code here)

        ; (at this point AX must contain the converted number)
        ret
str_to_int ENDP

Then, to use the procedure all you need to do is

lea dx, PARADATA
call str_to_int
; now AX contains the converted number

If I have been unclear let me know. Hope this helps.

PLEASE!!!

ANY PEOPLE, CAN PASTE "the Compleat Codes" of MULTIPLICATION HEX in Assembly.

PLEASE!!! Thanks.

commented: No, go away and sponge of someone else you loud-mouthed thread-digger -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.