I’m having some problems trying to solve this expression in assembler.
`$`z=(5*a-b/7)/(3/b+a*a)
I would like to know how do you convert a word to a double word ( unsigned solution ) ,
do i have to use the cwb command or do i use AX:BX , if i do have to use those last registers ,
how do i properly write the command ?
I will be testing the code in Turbo Debugger under DosBox .
My full code
assume cs:code,ds:data
data segment
;
a db ?
b db ?
rez dw ?
;
data ends
;
code segment
;
mov ax,data
mov ds,ax
;
;
;#####prima paranteza
;
mov al,a ;ah=a
mul 5 ;ax=a*5
mov cx,ax ;cx=ax
mov ah,b ; il mut pe ah in b ( pregatire pt conversie fara semn )
mov al,0 ; l-am convertit pe b in word ( pe 2 octeti )
div 7 ; am impartit double word-ul b la 7 , catul a ramas in ah , restul a ramas in al
sub cx,ax ; (am tinut cont de faptul ca in ax a ramas rezultatul dupa impartire ) , cx=cx-ax, a*5 - b/7
;
; ####a 2 a paranteza
;
mov ah,3
mov al,0 ; conversie de la b la w ( fara semn )
div b ; ax=3/b
mov bx,ax ; bx = ax
mov al,a
mul a ; ax = a * a
add ax,bx ; ax = ax + bx
;
;
; #### calcul final
mov bx,ax ; bx = ax ( rezultatul celei de a 2 a paranteze )
mov ax,cx ; ax = cx ( rezultatul primei paranteze )
word to double-word?
Let’s see if I got you:
word -> 8bit
double-word -> 16bit
AX, BX, CX and DX are 16 bit registers, and they are formed by two other 8-bit registers [ABCD]H and [ABCD]L, so, AX would be:
AH AL
|0|0|0|0|0|0|0|0| – |0|0|0|0|0|0|0|0|
When you use AX, you’re using those two at the same time. So, if you want to convert a word to a double word, you just clear the whole [ABCD]X register, and then move your word to the [ABCD]L register, leaving [ABCD]X with the word value.
Cheers