Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

manipulating 32 bit numbers with 16 bit registers in 8086

Im trying to write a program which get two 6-digit decimal numbers and show the addition of them, but in 16 bit 8086 i defined numbers as double word and put LO in WORD 1 and HO in word 2. similar to below code but i dont have any idea to do next, can any body suggest me algorithm for next operations? Thnx

x dd(?)
    next_no:
    mov cl,2
    mov ch,4

two_bit:
getch

sub al,30h
mov bl,10
mul bl
mov di,ax
add word ptr x+2,di

dec cl
jnz two_bit
fourbit:
getch
sub al,30h
mov bl,10
mul bl
mov di,ax
add word ptr x,di
dec ch
jnz fourbit

in this program di is a place to storing the number made through the loop when user enter a number di will multiple to 10 and the new digit will add to di like: proccess of getting 28 di=0*10+2=2 di=2*10*+8=28

like image 494
Amir Reza Asadi Avatar asked Dec 02 '11 06:12

Amir Reza Asadi


Video Answer


1 Answers

Rather than follow your uncommented code, I'll present an independent example.

Suppose you have one 32-bit number in DX:AX and one 32-bit number in CX:BX (this notation means that the high 16 bites are stored in DX for example, and the low 16 bits in AX). To add these values and leave the result in DX:AX, you would:

    add ax,bx
    adc dx,cx

The add instruction adds the two values and sets the C (carry) bit to 1 or 0 depending on whether there was a carry or not. The adc instruction adds the two values plus the value of the carry bit (and then sets the carry bit again). In this way, you can add values of any size by continuing with more adc instructions.

like image 117
Greg Hewgill Avatar answered Sep 17 '22 23:09

Greg Hewgill