Write an ARM assembly language program to translate the following sequence of statements . Assume x and y are memory locations that store two unsigned integers. Use the following: x is in R1, y is in R2, and z in R3. Make sure that your program works for any value of x and y.
if (x > 15)
{
x = 1;
if (y > 15) {
y = 2;
}
else {
y = y + 2;
}
}
else {
x = x + 1;
}
z = x + y;
I have solution but not sure! and it is not completed yet! (the solution should be something like that)
.global main
.func main
.text
.data
X : .word
Y :
Z :
Main :
Ldr r1, =x
Ldr r1, [r1]
Ldr r2, = y
Ldr r2, [r2]
Ldr r3, =z
Ldr r3, [r3]
Cmp r1, #15
Ble falseBlock
Mov r1, #2
else:
add r1, r1, #1
b end
add r3, r1, r2
end :
bx lr
main:
; storing the values
MOV %rsp, %rbp
SUB $48, %rsp
CALL __main
CMP $15, -4(%rbp)
J Loop2
;moving the values
MOV $1, -4(%rbp)
CMP $15, -8(%rbp)
;checkgin the condition
jle Loop3
MOV $2, -8(%rbp)
JMP Loop4
Loop3:
;going for the annother condition
ADD $2, -8(%rbp)
jmp Loop4
Loop2:
;going for the else condition
ADD $1, -4(%rbp)
Loop4:
; ending the last loop by finalizing the result
MOV -4(%rbp), %edx
MOV -8(%rbp), %eax
MOV %edx, %eax
MOV %eax, -12(%rbp)
MOV $0, %eax
ADD $48, %rsp
ENDP
END
Write an ARM assembly language program to translate the following sequence of statements . Assume x...
Write an ARM assembly language program to translate the following sequence of statements . Assume x and y are memory locations that store two unsigned integers. Use the following: x is in R1, y is in R2, and z in R3. Make sure that your program works for any value of x and y. if (x > 15) { x = 1; if (y > 15) { y = 2; } else { y =...
Section B - ARM Assembly Language (25 marks) An ARM instruction set summary is provided at the end of this paper 1. (5 marks) Consider the following assembly instruction STMFD r13!, (r5-6} Before executing this instruction, registers hold the following values: Register Value Register r9 Value r4 0x00400040 0x00000000 r5 r10 0x11223344 0x00800080 r6 0x55667788 r11 0x10001000 r7 0x99aabbcc r12 0x20002000 r8 exddeeff00 r13 ex40004000 What memory locations are affected after executing the above instruction? In a table, with a...
13) (4 pts) Squaring a number is useful in many other algorithms. This assembly routine calculates the square of an unsigned integer. How long does this take in clock cycles (worst case). Assume ARM 32 bit instruction set and the integer is in R0 before we begin. AREA L.textl, CODE, READONLY PROC EXPORT square square MOV R1,RO; CMP R1, #0 ANDS R3,RO,R1 BNE skip ADD RO,R1, LSL R3; MOV R2,R2, LSL #1 CMP R2, #0 BNE loop BX LR loop...
Question 2 ARM Assembly Language (25 marks) An ARM instruction set summary is provided at the end of this paper. (5 marks) Explain the difference between eor and eors instruction. Use an example to show why both forms are useful. а. b. (5 marks) Explain using an example what the "Idr r3, [r7,#4]" instruction does. c. (10 marks) The following is the assembly language generated by a C compile type mystery, %function mystery: args 0, pretend = 0, frame =...
Computer Architecture
Please help me explain the answer
3 For the following statement, translate the statement to ARM assembly code. Assume that variable fand g are each in register rO, r1. Base address of array A is in r3 and base address of array B is in r4. Temporary register is r5. f= g + A[B[3]] Ans) sol) LDR r5, 14, #12] ADD rs. r3. r5, LSL #2 LDR r5, [r3. #01 ADD rO, rl, r5
3 For the following...
Modify the ARMSIM program to do the following: 1) output the square sum of the data 2) output the sum of all negatives and positives separately .text @ Direvtive .global _start @ declare global begining _start: LDR R1,=idx @ content of idx is length of Vec and now R1 is a counter. LDR R1,[R1] @ R1 is now the length of Vec. read inderectly LDR R2,=Vec @ R2 is the address of first element of vector MOV...
Change this program in assembly language to loop until it encounters a sentinel value, which is a negative number. The data begins at x3100. Use only one branch command. There will always be at least one positive integer in the list. .ORIG x3000 LEA R1, xFF AND R3, R3, #0 AND R2, R2, #0 ADD R2, R2, #12 BRz #5 LDR R4, R1, #0 ADD R3, R3, R4 ADD R1, R1, #1 ADD R2, R2, #-1 BRnzp #-6 .END
Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of lower case to upper is provided below: Let’s look at a subroutine to capitalize all the lower-case letters in the string. We need to load each character, check to see if it is a letter, and if so, capitalize it. Each character in the string is represented with its ASCII code. For example, ‘A’ is represented with a 65 (0x41), ‘B’ with 66 (0x42),...
2. a)Write the ARM ALP conditional code snippet for the following statements written in C-language. Assume R1 to Rn as06 variables Let R1, R2, R3 contain the starting addresses of arrays X, Y and Z respectively Use Register R4 for variable i. Display appropriate messages. While (i+10) else Z[i] XiYi; b)i Write a program to display a message "This is an examination Question" on the screen using 06 a function sub program Note the following Address of the string to...
Given the following C Code segment convert it to ARM assembly. Assume the following register assignment have been made before your section of code begins. C Variable Register assignment r1 y r2 r3 r10 j r11 int x=0, y=0, z=0; int main() { for (int i = 0; i<10; i++) for (int j 0; j < 20; j++) if (i* j > 100) X++; if (i j >= 15) y++; + فہه Z = X + y; }