i have this code i have to translate it to machine code assembly language and this is really confusing
i have to right

``````x = 8
y = 12
if(x > y)
x = y - x
else
x = x - y
and

int  x = -5
int rslt = 0

while (x !=0)
{
rslt = rslt + x
x = x + 1
}``````

and i would really appericate it if any body could help me

2
Contributors
1
2
Views
8 Years
Discussion Span
Last Post by SamY
``````while (x !=0)
{
rslt = rslt + x
x = x + 1
}``````

and i would really appericate it if any body could help me

i think this is your answer, hope you know abit of assembly

``````x db 8d   ;defines a byte 8 in decimal
y db 12d
mov ax,[x]
mov bx, [y]
cmp ax,bx   ;compare the value of bx and ax
jg  x_more_y  ;jumps if more
sub bx,ax    ;subtract ax from bx
x_more_y:
sub ax,bx``````

now the fiisrt part has been solved
2nd part is also simple...

``````x db -5d
rslt db 0d
loop:
inc [rslt]
inc [x]   ;increment value of x
mov ax,[x]
cmp ax,0d
jne loop    ;if x!=0 then it will jump to the top of the loop. try it``````

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.