Question: Please note that you will write all functions in this homework in assembly. Please read all 4 functions Function 1 : int isNumber(char *c) Function
Please note that you will write all functions in this homework in assembly. Please read all 4 functions
Function 1 : int isNumber(char *c) Function should return 1 is the argument passed is a digit and zero otherwise. Please note the asci equivalents of numeric characters from an asci table.
.global isNumber .data // declare any global variables here .text isNumber: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return // Your solution here pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter Function 2 : Given the following C function prototype that accepts two integer arguments. Complete the function and return 1 if a > b , return -1 if a < b and return 0 if a is equal to b. Please write the function in assembly. Note that the assembly languge skeleton code is given in the attached .s file. int compare(int a, int b)
.global compare .data // declare any global variables here .text compare: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return // Your solution here pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter Function 3 : Given the following C function prototype which accepts an integer argument, complete the implementation of the function in Assembly language to return the number of 1s in the binary representation of the number passed. For example if the number is (011100011 ) then the function should return 5 as the number of 1s. Please remember that an integer is 32 bits long. Note that the assembly languge skeleton code is given in the attached .s file. int countOnes(int number)
.global countOnes .data // declare any global variables here countOnes compare: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return // Your solution here pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter Function 4: Write an assembly language function to determine the hamming distance ( the number of different bits) between two characters passed as parameter. Please note that the function prototype is given below and the function will be implemented in assembly language. Note that the assembly languge skeleton code is given in the attached .s file. int returnHammingDistance( char firstparameter, char secondparameter)
global returnHammingDistance .data // declare any global variables here returnHammingDistance compare: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return // Your solution here pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
