Question

Convert the high level language programming statementts to 80x86 assembly, Assume X=AX and y=BX for (i=1;...

Convert the high level language programming statementts to 80x86 assembly, Assume X=AX and y=BX

for (i=1; i<10; ++i){

x=x+1;

y=y-1;

}

if(x>=y)

y=x-1;

else

y=x+1;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question:

Convert the high level language programming statementts to 80x86 assembly, Assume X=AX and y=BX

for (i=1; i<10; ++i){

x=x+1;

y=y-1;

}

if(x>=y)

y=x-1;

else

y=x+1;

Answer with Clear Information:

Above High Level Code need to be modified as shown below to make it compatible with gcc/g++ compiler options.

Modified code is mentioned in bold

void main()

{

int i,x,y;

for (i=1; i<10; ++i){

x=x+1;

y=y-1;

}

if(x>=y)

y=x-1;

else

y=x+1;

}

After changing the above code, it was compiled and executed properly.

8086 Assembly Code for the same is written as follows:

==============================================

_i$ = -12 ; size = 4

_y$ = -8 ; size = 4

_x$ = -4 ; size = 4

_main PROC

push ebp

mov ebp, esp

sub esp, 12 ; 0000000cH

mov DWORD PTR _i$[ebp], 1

jmp SHORT $LN4@main

$LN2@main:

mov eax, DWORD PTR _i$[ebp]

add eax, 1

mov DWORD PTR _i$[ebp], eax

$LN4@main:

cmp DWORD PTR _i$[ebp], 10 ; 0000000aH

jge SHORT $LN3@main

mov ecx, DWORD PTR _x$[ebp]

add ecx, 1

mov DWORD PTR _x$[ebp], ecx

mov edx, DWORD PTR _y$[ebp]

sub edx, 1

mov DWORD PTR _y$[ebp], edx

jmp SHORT $LN2@main

$LN3@main:

mov eax, DWORD PTR _x$[ebp]

cmp eax, DWORD PTR _y$[ebp]

jl SHORT $LN5@main

mov ecx, DWORD PTR _x$[ebp]

sub ecx, 1

mov DWORD PTR _y$[ebp], ecx

jmp SHORT $LN1@main

$LN5@main:

mov edx, DWORD PTR _x$[ebp]

add edx, 1

mov DWORD PTR _y$[ebp], edx

$LN1@main:

xor eax, eax

mov esp, ebp

pop ebp

ret 0

_main ENDP

==============================================

Compile and Execute the above 8086 Assembly Code in 8085/8086 compatible operating systems. Validate and Verify the output results.

Add a comment
Know the answer?
Add Answer to:
Convert the high level language programming statementts to 80x86 assembly, Assume X=AX and y=BX for (i=1;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT