Question

I need to implement the following while loop in assembly: i = 1; while (i <=...

I need to implement the following while loop in assembly:

i = 1;

while (i <= 50) {

A[i] = i;

i++;

}

With the array of integers A stored at memory location x+200, where x is the address of the memory location where the assembly program is loaded.

I can only use following commands; LOAD, STORE, ARITHMETIC (ADD, SUB, MUL, DIV, INC), SKIP, BRANCHING (BLT, BGT, BLEQ, BGEQ, BEQ), READ and WRITE, and HALT

Homework Answers

Answer #1

Code in C++:-

int i = 1;

int A[51];

while (i <= 50) {

A[i] = i;

i++;

}

Code in Assembaly:-

#Refer Comments for better understanding:-

push rbp

mov rbp, rsp #Setting up stack pointers and base poiniters

sub rsp, 96

mov DWORD PTR [rbp-212], edi #Loading array base address

mov DWORD PTR [rbp-4], 1   #Initialisation of variable i.

.L3:

cmp DWORD PTR [rbp-4], 50 # Condition inside while loop.

jg .L4

mov eax, DWORD PTR [rbp-4]   

cdqe

mov edx, DWORD PTR [rbp-4] #Loading variable i into register edx.

mov DWORD PTR [rbp-208+rax*4], edx   #Assignment at array location A[i]=i.

add DWORD PTR [rbp-4], 1 #Increment of variable i.

jmp .L3 #continue with next iteration.

.L4:

nop

leave

ret

Know the answer?
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
Similar Questions
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
Please use loop and branch instructions to write an assembly code segment to do the following:...
Please use loop and branch instructions to write an assembly code segment to do the following: Read DIP switch. If DIP switch has the setting: b7 = b0 = 1, then, load A with number $11, load B with number $22, and do A+B; save the result to memory location $1000; if DIP switch has the setting: b4= b3 = 1, then, load A with number $55, load B with number $33, and do A-B; save the result to memory...
PLEASE SOLVE WILL RATE AND THUMBS UP Simple assembly code question: In this question you will...
PLEASE SOLVE WILL RATE AND THUMBS UP Simple assembly code question: In this question you will write a simple program to loop through an array (i.e., writing while statements in assembly) of non-zero numbers. Write an LC3 assembly program for converting a list of non-zero integers into their absolute values. The program starts at x3000. It will first load the address ARRAY of the start of the list into register R0. After this, R0 now contains the location in memory...
Assembly Programming in MIPS Write a program in MIPS assembler that performs the following computations: Prompts...
Assembly Programming in MIPS Write a program in MIPS assembler that performs the following computations: Prompts the user to enter two integers and stores the smaller one in the first data memory word (with the lowest address) and the larger one in the second data memory word. Then divides the larger word by the smaller one in integer and stores the integer quotient in the third data memory word and the remainder in the fourth data memory word. Finally, it...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit the program using your favorite code editor (e.g. Notepad++) and load the programs into QtSpim for execution. Activity Directions: Write a program that will read a line of text and determine whether or not the text is a palindrome. A palindrome is a word or sentence that spells exactly the same thing both forward and backward. For example, the string “anna” is a palindrome,...
Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of...
Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of MIPS instruction for the following pseudocode segment: A[3] = A[10] + B; Assume that B corresponds to register $t3 and the array A has a base address of 1000C41016 which is required to be loaded to register $t0 in your code. Provide comments for each line of your MIPS instruction. b) Assume that Loop starts at memory location 0xC010. Provide a) instruction format of...
Can i get the answer to these questions in detail explaining how you go to the...
Can i get the answer to these questions in detail explaining how you go to the solution 1.Convert to/from Hex (0) 2.Octal Binary Unsigned/ 2’s complement 3.Understand how to shift and rotate. 4.Understand the relationship between shifting and multiplication/division 5.Be able to recognize and use the following gates: AND OR NOT NAND NOR XOR 6.Understand how a half adder works Given a logical statement ((A OR B) AND NOT(C OR A)) show the gates. 7.What is the difference between an...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If ( n is even) { n = n / 2; } else { n = 3 * n + 1; } In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the...
You should now explore and document the following: 1. How can I watch a variable changing?...
You should now explore and document the following: 1. How can I watch a variable changing? 2. How can I watch the special function registers (SFR)? What does the program counter do when I step through my program? How does this relate to the program memory? 3. How does my C-code translate into assembly code? Can I simulate assembly commands? 4. Set the simulator to 16MHz (Project Properties -> Simulator) and use the Stopwatch to measure how long it takes...