Question

Given the following pseudo code: int result; (result is 1 byte) int count; (count is 1...

Given the following pseudo code:

int result; (result is 1 byte)

int count; (count is 1 byte)

for (result= 10, count= -10; count < result ; count++) {

if(count > 2) result--;

else result ++;

}

1) write an assembly language program that will implement this pseudo code using a while construct.

2) write an assembly language program that will implement this pseudo code using a do-until construct

Note: For both 1) and 2), do not forget to include the data section in your program. count and result are 1-byte variables to be implemented in memory, not in registers. Your assembly program must match the pseudo code 1-to-1 (this also means that you should use a conditional branch that correctly implements the loop condition; BNE or BEQ branches are not allowed). Use labels such as IF, ENDIF, WHILE, ENDWHILE, DO, ENDDO, to show where your If/While/Do-Until constructs are. Do not forget the data section.

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

1. Assembly language using while construct:

Section .data

result DB 0 // one byte memory variable

count DB 0

section .text

start:

mov result, #10 // initialisation

mov count, #-10

WHILE: cmp count,result   

BGE ENDWHILE // if count greater than -//or equal to result end while

IF: cmp count, #2   

BLE ELSE // branch to else if count less //than or equal to 2

DEC [result]
jmp BOTH

ELSE: INC [result]
BOTH: INC [count]. // increasing loop //counter
JMP WHILE // jumping to while

ENDWHILE: end start


2. Using do-until

Section .data

result DB 0

count DB 0

section .text

start:

mov result, #10

mov count, #-10

DO:

IF: cmp count, #2

BLE ELSE

DEC [result]
jmp BOTH

ELSE: INC [result]

BOTH: INC [count]

CMP count,result
BLE DO // branch if count less than or //equal to result

end start

Add a comment
Know the answer?
Add Answer to:
Given the following pseudo code: int result; (result is 1 byte) int count; (count is 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