Question

In: Computer Science

Write a complete ARM asembly program for following code: g=12, h=8, i=2, j=5; f = (g...

Write a complete ARM asembly program for following code:

g=12, h=8, i=2, j=5;

f = (g + h) - (i + j);

Your program displays the message:

f = (g + h) – (i + j) = 13

Note that 13 should be calculated, not hardcoded

Below is my current code:

.global _start

_start:

mov R0,#12

mov R1,#8

mov R2,#2

mov R3,#5

add R4,R0,R1

add R5,R2,R3

sub R6,R4,R5

How should I display the message: "f = (g + h) – (i + j) ="? And my code keeps giving me "Bad instruction" errors? How can I fix it?

Solutions

Expert Solution

Your required answer for the above problems is below  -

Code -

# Program to give expression result with printed expression 
.data   ## Data declaration section
        ## String to be printed:
out_string: .asciiz "\nf = (g + h) - (i + j) = "

.text   ## Assembly language instructions go in text segment
main:   ## Start of code section

        li $t0, 12              # Initialize g = 12
        li $t1, 8               # Initialize h = 8
        li $t2, 2               # Initialize i = 2
        li $t3, 5               # Initialize j = 5

        add $t4, $t0, $t1       # Add $t4 = g + h
        add $t5, $t2, $t3       # Add $t5 = i + j
        sub $t6, $t4, $t5       # Sub $t6 = $t4 - $t5

        li $v0, 4               # system call code for printing string = 4
        la $a0, out_string      # load address of string to be printed into $a0
        syscall                 # call operating system to perform operation
                                # specified in $v0
                                # syscall takes its arguments from $a0, $a1, ...
        
        move $a0, $t6           # load return value from $t6 to argument $a0.
        li $v0, 1               # load syscall print_int into $v0.
        syscall

        li $v0, 10              # terminate program
        syscall

## end of exp.asm

Output -

Note :- I have commented wherever it is required to make you understand the program,
 still you find any difficulty in understanding anything in the program then let me know.
 If you are happy with my response then please give positive feedback. Thanks
.global main

main:

mov r0, #12

mov r1, #8

mov r2, #2

mov r3, #5

add r4, r0, r1

add r5, r2, r3

sub r6, r4, r5

ldr r7, =message

ldr r8, =len

mov r9, #1

SWI 0

.data
message:
.ascii "\nf = (g + h) - (i + j) = "
len = .-message

.end


Related Solutions

Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g +...
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note that 13 should be calculated, not hardcoded
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j a. How many bits does it take to encode ? b. How many bits needed in register file to store the data?
Consider the following bivariate data. Point A B C D E F G H I J...
Consider the following bivariate data. Point A B C D E F G H I J x 0 1 1 2 3 4 5 6 6 7 y 5 5 6 5 4 3 2 0 1 1 (a) Construct a scatter diagram of the given bivariate data. (Do this on paper. Your instructor may ask you to turn in this work.) (b) Calculate the covariance. (Give your answer correct to two decimal places.) (c) Calculate sx and sy. (Give...
Consider the following demand curve: A B C D E F G H I J P...
Consider the following demand curve: A B C D E F G H I J P $0.50 $0.45 $0.40 $0.35 $0.30 $0.25 $0.20 $0.15 $0.10 $0.05 QD 1 2 4 6 9 12 16 20 25 30 Calculate elasticities for pairs of points to check statements that were made during class and in the text. When making the calculations, use average price and average quantity for the two points. The formula for this should be in your notes. It is...
If f and g are both differentiable functions. If h = f g, then h'(2) is: ___________________
  If f and g are both differentiable functions. If h = f g, then h'(2) is: ___________________ Given the function: y=sin(4x)+e^-3x and dx/dt = 3 when x=0. Then dy/dt = ________________ when x=0. Let f(x) = ln (√x). The value of c in the interval (1,e) for which f(x) satisfies the Mean Value Theorem (i.e f'(c)= f(e)-f(1) / e-1 ) is: _________________________ Suppose f(x) is a piecewise function: f(x) = 3x^2 -11x-4, if x ≤ 4 and f(x) =...
1. ¬B∨(G↔J), H→(B&C) ∴(H&J)→G 2. A∨B, C↔¬(B∨D) ∴C→A 3. (A&B) ↔ (F→G), (A&F) & B∴(G→R)→R 4....
1. ¬B∨(G↔J), H→(B&C) ∴(H&J)→G 2. A∨B, C↔¬(B∨D) ∴C→A 3. (A&B) ↔ (F→G), (A&F) & B∴(G→R)→R 4. T→¬B, T→¬D ∴ T→¬(B∨D) 5. ¬(M∨¬S), S→(R→M) ∴A → (¬R∨T) 6. (F&G) → I, (I∨J) → K ∴F→(G→K) 7. ¬U, O→G, ¬(O∨G) →U ∴G Prove that the arguments are valid by constructing a dedication using the rules MP, MT, DN, Conj, Simp, CS, Disj, DS, DM, CP, HS, BE, and DL. Use CP if needed.
Computer Architecture: Write a MIPS program to compute f = g - (f + 5) Assume...
Computer Architecture: Write a MIPS program to compute f = g - (f + 5) Assume registers $to, $s1 hold values for g and f respectively. The program should display the following prompts and read value entered by the user “Enter a value for f:" “Enter a value for g:" The program the prints: "Answer for f = g - (f + 5):" The program should repeat the above steps 3 times for each input pair, f and g Make...
Consider a 2^8-3 fractional factorial design with design generators F=ABC, G=ABD, and H=BCDE a)Find the complete...
Consider a 2^8-3 fractional factorial design with design generators F=ABC, G=ABD, and H=BCDE a)Find the complete defining relation and generate the alias structure using the principle(positive) fraction. Second, determine the design resolution (you need to show your justification). b)List the basic variables and the design configuration (All 32 design points with the + and – signs. You should show the setting for all 8 factors by using the design generators) (Hint: Here there are 5 basic variables which you can...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values. C= 5* (F - 32) / 9 F = (9 * C / 5 ) + 32 My code below: TempConvert.s LDR R8,=temperature LDR R1,[R8] LDR R8,=unit LDRB R2,[R8] LDR R8,=celsius LDRB R3,[R8] LDR R8,=fahrenheit LDRB R4,[R8] MOV R6,#9...
**Add comments to ARM code to explain steps** Write an ARM assembly program to convert temperatures...
**Add comments to ARM code to explain steps** Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values. C= 5* (F - 32) / 9 F = (9 * C / 5 ) + 32 TempConvert.s LDR R8,=temperature LDR R1,[R8] LDR R8,=unit LDRB R2,[R8] LDR R8,=celsius LDRB R3,[R8] LDR R8,=fahrenheit LDRB R4,[R8] MOV R6,#9 MOV R7,#5 ;----C =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT