Assembly Programming: How to Calculate 3a-4c Using MUL Instruction

Click For Summary
SUMMARY

The forum discussion addresses the calculation of the expression 3a - 4c using the MUL instruction in assembly programming. The original code provided by the user contains errors, particularly in the handling of the multiplication results and the storage of intermediate values. Key corrections include changing MOV SI, AX to MOV SI, CX and ensuring that the multiplication results are correctly managed to avoid overwriting important data. The final solution emphasizes proper data placement and the correct use of registers for accurate calculations.

PREREQUISITES
  • Understanding of x86 assembly language syntax
  • Familiarity with the MUL instruction and its behavior
  • Knowledge of register usage in assembly programming
  • Basic concepts of data segment organization in assembly
NEXT STEPS
  • Study the x86 assembly language register architecture
  • Learn about the implications of using the MUL instruction with different data types
  • Explore effective data segment management in assembly programs
  • Investigate debugging techniques for assembly language programs
USEFUL FOR

Assembly programmers, computer science students, and anyone interested in low-level programming and optimization techniques in x86 architecture.

risen375
Messages
1
Reaction score
0
Im having trouble with this program. It is suppose to calculate 3


call getPos ;AX = a (user input)
M1 dw ?
mov M1, AX ;M1 = a
call crlf
call getPos ;AX = b (user input)
M2 dw ?
mov M2, AX ;M2 = b
call crlf
call getPos ;AX = c (user input)
M3 dw ?
mov M3, AX ;M3 = c
call crlf
mov BX, 2 ;BX = 2
mov CX, 3 ;CX = 3
mov DX, 4 ;DX = 4
mov AX, M1 ;AX = a
mul CX ;AX= 3*a
mov SI, AX ;SI = 3a
mov AX, M3 ;AX = M3
mul DX ;AX = 4*c
mov DI, AX ;DI = 4c
sub SI, DI ;3a-4c
mov AX, SI ;AX = 3a-4c
call putPos ;the sum (being in AX) is displayed
mov ah, 04c
int 021
include ioSubs.inc
 
Technology news on Phys.org
Hey risen375 and welcome to the forums.

Try changing MOV SI,AX to MOV SI,CX. Also try changing MOV DI,AX to MOD DI,DX.

If I recall correctly, the first operand is the register where something is actually stored to not the second one.
 
You should not put data in the middle of your program. If you're going to have code and data in the same segment, the data usually goes after the code. Another problem with your program is that the result of a multiply ends up in DX:AX as a 32 bit values, which is probably setting DX to zero every time you do a MUL. Your code could look like this.

call getpos ; get a
mov m1,ax
...
mov ax,3 ; ax=3a
mul m1
...
mov ah, 04ch ;exit program
int 21h

m1 dw ? ;program data
m2 dw ?
m3 dw ?
 
Last edited:

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K