For this quiz, you must write an implementation of the function get_bit in ARM a
ID: 3798063 • Letter: F
Question
For this quiz, you must write an implementation of the function get_bit in ARM assembly language: int get_bit(int *data, int size, int desired); The function accepts a pointer to an array of integers and the size of the array in words. It sets or clears the desired bit, where desired is an integer bit number. If the value of setto is zero, set the bit to zero. If the value of setto is non-zero (any possible value), set the bit to a one. For example, suppose the function is passed these two values in the array. They are in binary as passed to the function, but I have expressed them as hexadecimal here: c4a16062 Id8ebb48 set_bit(data, 2, 0, 0) will clear the high order bit of the first value, changing it to 44a16062. set_bit(data, 2, 31, 1) will set the low bit of the first value to true, changing the value to 44a16063. set_bit(data, 2, 32, 1) will set the high bit of the second word to true, changing the value to 9d8ebb48. Bits 0-31 are the first word, 32-63 are the second word, and so on. If a value is supplied to desired that is outside the range of possible values, do nothing (certainly, don't crash). The program quiz system is persistent, meaning your program will remain in the window below until the assignment closes.Explanation / Answer
get_bit(int*, int, int):
sub sp, sp, #16
str x0, [sp, 8]
str w1, [sp, 4]
str w2, [sp]
ldr w1, [sp]
ldr w0, [sp, 4]
cmp w1, w0
ble .L2
mov w0, -1
b .L3
.L2:
ldrsw x0, [sp]
lsl x0, x0, 2
ldr x1, [sp, 8]
add x0, x1, x0
ldr w0, [x0]
.L3:
add sp, sp, 16
ret
---------------------------------------------------------------------------------------------------------------------------------------------------------
int get_bit(int *data, int size, int desired) {
if(desired > size) { // checking with in limit or not
return -1;
}
return data[desired]; // returns desired value
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.