I have code example for multiplying two 16 bit numbers on 8086 and trying to update it for two 32 bit numbers multiplying.
start:
MOV AX,0002h ; 16 bit multiplicand
MOV BX,0008h ; 16 bit multiplier
MOV DX,0000h ; high 16 bits of multiplication
MOV CX,0000h ; low 16 bits of multiplication
MOV SI,10h ; loop for 16 times
LOOP:
MOV DI,AX
AND DI,01h
XOR DI,01h
JZ ADD
CONT:
RCR DX,1
RCR CX,1
SHR AX,1
DEC SI
CMP SI,0
JNZ LOOP
JMP END ; ignore here, it's not about multiplication.
ADD:
ADD DX,BX
JMP CONT
Code statements above multiply two 16 bit numbers.
To update it for 32 bit two numbers, I know I need updates like:
- Change
AX
to00000002h
andBX
to00000008h
. - Use two more registers (I don't know which registers I should use) to hold second and third 16 bits of multiplication (because multiplication will be 64 bit. 16 bit for 4 times. I currently have DX and CX.)
- Update loop number to
20h
(SI
in that case) (that makes 32 times for 32 bit number)
8086 is 16-bit microprocessor so its registers are. I can't assign registers 32-bit-long numbers.
8086's registers:
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
SREG: DS, ES, SS, and only as second operand: CS.
Source: http://www.electronics.dit.ie/staff/tscarff/8086_instruction_set/8086_instruction_set.html
My questions are:
- How can I handle two different registers for one 32-bit number. (registers are 16-bit, so I have to split the number into two registers)
- What registers can I use for that purpose? Am I free to use any register arbitrarily?
Thanks in advance.