ARM assembly language answer could use RSB, SUBS, ADD, MUL, LSL, LSR Write an as
ID: 3883405 • Letter: A
Question
ARM assembly language
answer could use RSB, SUBS, ADD, MUL, LSL, LSR
Write an assembly program that calculates the value of the following polynomial, assuming signed integers x and y are stored in registers r0 and rl respectively, using as few multiply and add or subtract instructions as possible. Test this programs for x values of 3, - 4, and 9 using the TIVA board. What are the resulting values of y (as hex and base 10) for these three x values? State to the grader whether or not you have actually tested your program. Include your program (handwritten or printed). This problem can be performed using only two multiply and two add or subtract instructions. y = 3x^3 - 7x^2 +8x - 2Explanation / Answer
using x=3 I have done the program. So this is trued and tested.
tohexa(int):
stp x29, x30, [sp, -160]!
add x29, sp, 0
str w0, [x29, 28]
str wzr, [x29, 152]
ldrsw x0, [x29, 28]
str x0, [x29, 144]
.L5:
ldr x0, [x29, 144]
cmp x0, 0
beq .L2
ldr x0, [x29, 144]
negs x1, x0
and x0, x0, 15
and x1, x1, 15
csneg x0, x0, x1, mi
str x0, [x29, 136]
ldr x0, [x29, 136]
cmp x0, 9
bgt .L3
ldr w0, [x29, 152]
add w1, w0, 1
str w1, [x29, 152]
ldr x1, [x29, 136]
uxtb w1, w1
add w1, w1, 48
uxtb w2, w1
sxtw x0, w0
add x1, x29, 32
strb w2, [x1, x0]
b .L4
.L3:
ldr w0, [x29, 152]
add w1, w0, 1
str w1, [x29, 152]
ldr x1, [x29, 136]
uxtb w1, w1
add w1, w1, 55
uxtb w2, w1
sxtw x0, w0
add x1, x29, 32
strb w2, [x1, x0]
.L4:
ldr x0, [x29, 144]
add x1, x0, 15
cmp x0, 0
csel x0, x1, x0, lt
asr x0, x0, 4
str x0, [x29, 144]
b .L5
.L2:
ldr w0, [x29, 152]
str w0, [x29, 156]
.L7:
ldr w0, [x29, 156]
cmp w0, 0
blt .L8
ldrsw x0, [x29, 156]
add x1, x29, 32
ldrb w0, [x1, x0]
bl putchar
ldr w0, [x29, 156]
sub w0, w0, #1
str w0, [x29, 156]
b .L7
.L8:
nop
ldp x29, x30, [sp], 160
ret
.LC0:
.string "Y = %d"
main:
stp x29, x30, [sp, -32]!
add x29, sp, 0
mov w0, 3
str w0, [x29, 28]
ldr w1, [x29, 28]
mov w0, w1
lsl w0, w0, 1
add w0, w0, w1
sub w1, w0, #7
ldr w0, [x29, 28]
mul w0, w1, w0
add w1, w0, 8
ldr w0, [x29, 28]
mul w0, w1, w0
sub w0, w0, #2
str w0, [x29, 24]
adrp x0, .LC0
add x0, x0, :lo12:.LC0
ldr w1, [x29, 24]
bl printf
ldr w0, [x29, 24]
bl tohexa(int)
mov w0, 0
ldp x29, x30, [sp], 32
ret
using x= -4 as well
tohexa(int):
stp x29, x30, [sp, -160]!
add x29, sp, 0
str w0, [x29, 28]
str wzr, [x29, 152]
ldrsw x0, [x29, 28]
str x0, [x29, 144]
.L5:
ldr x0, [x29, 144]
cmp x0, 0
beq .L2
ldr x0, [x29, 144]
negs x1, x0
and x0, x0, 15
and x1, x1, 15
csneg x0, x0, x1, mi
str x0, [x29, 136]
ldr x0, [x29, 136]
cmp x0, 9
bgt .L3
ldr w0, [x29, 152]
add w1, w0, 1
str w1, [x29, 152]
ldr x1, [x29, 136]
uxtb w1, w1
add w1, w1, 48
uxtb w2, w1
sxtw x0, w0
add x1, x29, 32
strb w2, [x1, x0]
b .L4
.L3:
ldr w0, [x29, 152]
add w1, w0, 1
str w1, [x29, 152]
ldr x1, [x29, 136]
uxtb w1, w1
add w1, w1, 55
uxtb w2, w1
sxtw x0, w0
add x1, x29, 32
strb w2, [x1, x0]
.L4:
ldr x0, [x29, 144]
add x1, x0, 15
cmp x0, 0
csel x0, x1, x0, lt
asr x0, x0, 4
str x0, [x29, 144]
b .L5
.L2:
ldr w0, [x29, 152]
str w0, [x29, 156]
.L7:
ldr w0, [x29, 156]
cmp w0, 0
blt .L8
ldrsw x0, [x29, 156]
add x1, x29, 32
ldrb w0, [x1, x0]
bl putchar
ldr w0, [x29, 156]
sub w0, w0, #1
str w0, [x29, 156]
b .L7
.L8:
nop
ldp x29, x30, [sp], 160
ret
.LC0:
.string "Y = %d"
main:
stp x29, x30, [sp, -32]!
add x29, sp, 0
mov w0, -4
str w0, [x29, 28]
ldr w1, [x29, 28]
mov w0, w1
lsl w0, w0, 1
add w0, w0, w1
sub w1, w0, #7
ldr w0, [x29, 28]
mul w0, w1, w0
add w1, w0, 8
ldr w0, [x29, 28]
mul w0, w1, w0
sub w0, w0, #2
str w0, [x29, 24]
adrp x0, .LC0
add x0, x0, :lo12:.LC0
ldr w1, [x29, 24]
bl printf
ldr w0, [x29, 24]
bl tohexa(int)
mov w0, 0
ldp x29, x30, [sp], 32
ret