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

In summary, the program is intended to calculate the result of 3a-4c, but there are a few issues that need to be addressed. The data should be placed after the code, and the result of the multiplication needs to be stored in the correct registers. Additionally, the code should end with the proper interrupt call to exit the program.
  • #1
risen375
1
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
  • #2
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.
 
  • #3
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:

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

1. What is Assembly Programming?

Assembly Programming is a low-level programming language that is used to directly communicate with a computer's hardware. It is often used for tasks that require a high level of control over the computer's resources, such as writing operating systems, device drivers, and embedded systems.

2. Why is Assembly Programming important?

Assembly Programming is important because it allows for precise and efficient control over a computer's hardware, making it ideal for tasks that require high performance and low-level access. It is also essential for understanding how computers and their components work at a fundamental level.

3. Is Assembly Programming difficult to learn?

Assembly Programming can be challenging to learn, especially for those who are new to programming. It requires a solid understanding of computer architecture and a different way of thinking compared to high-level programming languages. However, with dedication and practice, it can be mastered.

4. What are some common applications of Assembly Programming?

Assembly Programming is commonly used in the development of operating systems, device drivers, and other system software. It is also used in embedded systems, such as microcontrollers, and for optimizing critical code sections in high-level programs for improved performance.

5. Are there any resources available for help with Assembly Programming?

Yes, there are many online resources available for learning and getting help with Assembly Programming. These include tutorials, forums, and communities where experienced programmers can offer guidance and support. There are also books and courses available for those who prefer a more structured learning approach.

Similar threads

Back
Top