0

Here is a 32x16 bit code i have made (12345678x1011)

MYCODE SEGMENT
 ASSUME cs:MYCODE
 ORG 1000h
START: nop
L1: mov ax, cs
    mov ds, ax
    mov sp, ax
    
    
L2: mov ax, 5678h
    mov cx, 1011h
    
L3: MUL cx
    mov WORD PTR ds:[5000h],ax
    mov bx,dx
    
L4: mov ax, 1234h
    mov cx, 1011h
L5: MUL cx 
    add ax,bx
    mov WORD PTR ds:[5002h],ax
    mov WORD PTR ds:[5004h],dx
    HLT
    
L6: mov ah, 4CH
    INT 21H

MYCODE ENDS
 END START

To get answer i stored first AX in the 5000h & 5001h location and moved DX to BX then on next multiplication i added AX,BX and stored it in 5002h and 5003h and the rest of the DX in 5004h and forward. But I am unable to catch the logic to do 32x32 multiplication and tried to do this code but is wrong output and tried to do hand written math but not able to find the solution The 32x32 i tried is (12345678x12345678)

MYCODE SEGMENT
 ASSUME cs:MYCODE
 ORG 1000h
START: nop
L1: mov ax, cs
    mov ds, ax
    mov sp, ax
    
    
L2: mov ax, 5678h
    mov cx, 5678h
    
L3: MUL cx
    mov WORD PTR ds:[5000h],ax
    mov bx,dx
    
L4: mov ax, 1234h
    mov cx, 5678h
L5: MUL cx 
    add ax,bx
    mov WORD PTR ds:[5002h],ax
    mov bx,dx
    
    
    
L6: mov ax, 5678h
    mov cx, 1234h
    
L7: MUL cx
    add ax,bx
    mov WORD PTR ds:[5004h],ax
    mov bx,dx
    
L8: mov ax, 1234h
    mov cx, 1234h
L9: MUL cx 
    add ax,bx
    mov WORD PTR ds:[5006h],ax
    mov WORD PTR ds:[5008h],dx
    HLT
    
L10: mov ah, 4CH
    INT 21H

MYCODE ENDS
 END START
  • `mov sp, ax` seems unlikely to be a good idea, especially when you don't also set SS. But just in general, setting the stack pointer to a segment base seems unwise; it might be an odd number, and you don't know what offset you're going to get within the SS segment. – Peter Cordes Jun 08 '21 at 07:38
  • Your code is missing any `adc` instructions. There's possibility of carry-out into higher chunks from the 2nd and higher components when doing a full multiply, like you 32x32 => 64-bit. – Peter Cordes Jun 08 '21 at 07:40
  • Related: [Assembly multiplication](https://stackoverflow.com/q/40310666) shows 16x32 => 48-bit with `adc` as necessary, which yours is missing. [Multiplying 64-bit number by a 32-bit number in 8086 asm](https://stackoverflow.com/q/55485709) shows the general idea of how to think about the math going on, breaking up into chunks and what they represent in the actual math you're doing. [Multiplying 32 bit two numbers on 8086 microprocessor](https://stackoverflow.com/a/60015995) shows how to do the 32x32 => 32-bit low part (3 mul and some add; no adc needed) – Peter Cordes Jun 08 '21 at 08:00
  • Ah, finally found an existing Q&A that matches your problem. [multiply two 32-bit numbers to get a 64-bit number, on a 8086 (32x32 => 64-bit with 16-bit multiplies)](https://stackoverflow.com/q/13451628). This is a duplicate, unless you need more explanation of why add-with-carry is needed. – Peter Cordes Jun 08 '21 at 08:40

0 Answers0