Write an assembly program SPARC to find the maximum of x3 1
Write an assembly program (SPARC) to find the maximum of x^3 + 14x^2 + 56x - 64 where x is in the range of (-2 =< x <= 8).
Solution
The maximum of x^3 + 14x^2 + 56x - 64 where x is in the range of (-2 =< x <= 8):
The maximum value should be 5 when x = 3
Assembley Program:
main:
save %sp, -96, %sp
ba test
mov -2, %a_r
loop:
mov %x_r, %00 !x_r moved into 00
mov %x_r, %01 !x_r moved into 01
call .mul !multiplied and stored in 00
call .mul !multiplied again and stored in 00
mov %00, r0 !results stored in r0
mov %x_r, %00 !x_r moved into 00
mov %x_r, %01 !x_r moves into 01
call .mul !multiplied and stored in 00
mov 14, %01
call .mul !00 result is multiplied by 14 and stored in r1
mov %00, r1
mov 56, %00 !56 moved into 00
mov %x_r, %01 !x_r moved into 01
call .mul !multiplied and stored in r2
mov %00, r2
Add r0,r1,r0 !r0+r1 stored in r0
Add r0,r2,r0 !r0+r2 stored in r0
Sub r0,64,r0 !r0-64 stored in r0
add %x_r, 1, %x_r !a_r + 1
test:
cmp %x_r %b_r ! x_r<=8?
ble loop
