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.
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
Given the following pseudo code: int result; (result is 1 byte) int count; (count is 1...
What will be left in a and b after the execution of the pseudo code below? Draw a flowchart for the code. a=4 b=10 while (a is less than b) do if (b is less than 12) then b=b+3 else a a +1 b b+2 endif a=a+1 while (b is greater than or equal to 14) do b=b-1 endwhile endwhile b=b+ 100 What will be left in a and b after the execution of the pseudo code below? Draw a...
For the C code 1 int loop while(int a, int b) int result 1; while (a < b) t result (atb); return result; Gcc generates the following assembly code: %ebp+8, mov1 movl movl %ebp+12 at 8(%ebp) ,%ecx 12(%ebp) ,%ebx $1,%eax a at b 5 jge L11 leal (%ebx, %ecx), Xodx 8 L12: inull %eax , %eax addl $1,%ecx addl $1, edx cmp1 %ecx , %ebx 9 10 12 13 J8 14 ·L11: .L12 In generating this code, occ makes an...
its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...
What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...
Thie What is the output of the following program segment? int count 1; do System.out.print(count (count-) + while(count++ <= 5);
1. [2 points] Write a MIPS assembly language program of the following C function and the code to call the function: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; مهه Arguments g, h, i, and j are passed to the function in registers $a0, $al, Şa2, and $a3, respectively while f in $50 (hence, need to save $50 on stack), and the result is to be stored...
How do i finish this code: #include <stdio.h> int main() { long long decimal, tempDecimal, binary; int reminder, weight = 1; binary = 0.0; //Input decimal number from user printf("Enter any decimal number: "); scanf("%lld", &decimal); // Since we do not want change the value of decimal in the code // let us use tempDecimal to store the value of decimal tempDecimal = decimal; printf("\n\n"); // Let us use while loop first to implement printf("while loop part:\n"); /**************START FROM HERE...
Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like C or Java. It does not need to run for me, but the code should be included in a text document called FirstnameLastnameHLA3.txt along with your assignment submission. Implement the program in MIPSzy Assembly language. Use the high level code as comments to the right of the Assembly code as the textbook does. If you write that MIPSzy...
third photo is problem 8 pt 2. anything would help please Problem 7 (15pts) Convert this following pseudo-code in high level language into a piece of an assembly code (NIOS 2). In the following pseudo-code in high level language, r4, r5, r6, and r10 represent registers 4,5, 6, and 10, respectively Consider this pseudo-code in high level language: If ! (r4 >r5 or rs <r6) r10=r10+1 else r10- r10-1 This becomes the following piece in assembly code (put you answers...
1. Assume that you are given values in eax, ebx, ecx. Write an assembly code that does the following: eax = (ecx + edx ) - (eax + ebx) 2. Write a piece of code that copies the number inside al to ch. Example: Assume that Initially eax = 0x15DBCB19. At the end of your code ecx = 0x00001900. Your code must be as efficient as possible. 3. You are given eax = 0x5. Write one line of code in...