Write ARM assembly implementations for all of the functions below. The functions must be present in a single .s file. Your function/procedure names must be identical to that presented below, as your implementations will be tested with generic C code used by the TAs. All of your functions must return a value such that the program will run to completion with no segmentation faults. If a function cannot be successfully implemented, it still must return a valid value: no function may be omitted. Attempting to omit a function will result in a compile error.
CSE 2312 Programming Assignment 1 – Fall 2021 Programming Lab Policies: • Labs that fail to compile, or do not terminate correctly, will receive a zero. • Labs that fail to compile, or do not terminate correctly, may not be resubmitted for a grade. This includes instances where students did not upload the correct file for grading. • All labs must be submitted via the upload link on Canvas. Labs are not accepted through e-mail or Canvas Messenger. • Students must make a credible attempt to pass all programming labs to receive a passing grade in the course. Write ARM assembly implementations for all of the functions below. The functions must be present in a single .s file. Your function/procedure names must be identical to that presented below, as your implementations will be tested with generic C code used by the TAs. All of your functions must return a value such that the program will run to completion with no segmentation faults. If a function cannot be successfully implemented, it still must return a valid value: no function may be omitted. Attempting to omit a function will result in a compile error. A sample driver is included with this lab for student convenience. It is the student’s responsibility to test their program with a sufficient range of values to ensure their code functions correctly. Programs will be tested with different values than are used in the sample driver. Submit your assignment via the submission link on Canvas. The name of this file should be lab#_lastname_loginID.s. Example: If your name is John Doe and your login ID is jxd1234, your submission file name must be “lab#_Doe_jxd1234.s”. Labs uploaded as a zip file, or labs that require a custom makefile, will receive a zero. All questions worth nine points, unless otherwise noted. 1. uint64_t add64 (uint32_t x, uint32_t y) // returns x + y; worth 10 points 2. uint64_t sub64 (uint64_t x, uint64_t y) // returns x - y 3. int16_t minS16(int16_t x, int16_t y) // returns the minimum of x, y 4. uint8_t minU8(uint8_t x, uint8_t y)// returns the minimum of x, y 5. bool isLessThanU32(uint32_t x, uint32_t y) // returns 1 if x < y,="" 0="" else="" 6.="" bool="" islessthans8(int8_t="" x,="" int8_t="" y)="" returns="" 1="" if="" x="">< y,="" 0="" else="" 7.="" uint16_t="" shiftleftu16="" (uint16_t="" x,="" uint16_t="" p)="" returns="" x="">< p="x" *="" 2p="" for="" p="0" ..="" 8="" 8.="" uint16_t="" shiftu16(uint16_t="" x,="" int16_t="" p)="" return="" x="" *="" 2p="" for="" p="-16" ..="" 16="" 9.="" int8_t="" shifts8="" (int8_t="" x,="" int8_t="" p)="" return="" x="" *="" 2p="" for="" p="-8" ..="" 8="" 10.="" bool="" isequals16(int16_t="" x,="" int16_t="" y)="" returns="" 1="" if="" x="y," 0="" if="" x="" !="y" 11.="" bool="" isequalu32(uint32_t="" x,="" uint32_t="" y)="" returns="" 1="" if="" x="y," 0="" if="" x="" !="y" all="" available="" conditionals="" are="" on="" page="" 1-19="" (39)="" of="" the="" arm="" 7="" reference="" manual.="" keep="" in="" mind="" that="" signed="" and="" unsigned="" integers="" may="" require="" different="" conditionals.="" *="" cse="" 2312="" -="" fall="" 2021="" -="" lab="" 1="" driver="" *="" *="" programming="" lab="" policies:="" *="" -="" labs="" that="" fail="" to="" compile,="" or="" do="" not="" terminate="" correctly,="" will="" receive="" a="" zero.="" *="" -="" labs="" that="" fail="" to="" compile,="" or="" do="" not="" terminate="" correctly,="" may="" not="" be="" resubmitted="" for="" a="" grade.="" *="" this="" includes="" instances="" where="" students="" did="" not="" upload="" the="" correct="" file="" for="" grading.="" *="" -="" all="" labs="" must="" be="" submitted="" via="" the="" upload="" link="" on="" canvas.="" labs="" are="" not="" accepted="" through="" *="" e-mail="" or="" canvas="" messenger.="" *="" -="" students="" must="" make="" a="" credible="" attempt="" to="" pass="" all="" programming="" labs="" to="" receive="" a="" passing="" *="" grade="" in="" the="" course.="" *="" *="" all="" values="" are="" example="" values="" only="" -="" student="" programs="" will="" be="" evaluated="" with="" *="" different="" inputs.="" students="" are="" expected="" to="" test="" their="" code="" with="" different="" *="" values="" to="" ensure="" their="" code="" functions="" correctly.="" *="" */="">
#include #include #include extern uint64_t add64(uint32_t x, uint32_t y); // 1. returns x + y extern uint64_t sub64(uint64_t x, uint64_t y); // 2. returns x - y extern int16_t minS16(int16_t x, int16_t y); // 3. returns the minimum of x, y extern uint8_t minU8(uint8_t x, uint8_t y); // 4. returns the minimum of x, y extern bool isLessThanU32(uint32_t x, uint32_t y); // 5. returns 1 if x < y,="" 0="" else="" extern="" bool="" islessthans8(int8_t="" x,="" int8_t="" y);="" 6.="" returns="" 1="" if="" x="">< y,="" 0="" else="" extern="" uint16_t="" shiftleftu16="" (uint16_t="" x,="" uint16_t="" p);="" 7.="" returns="" x="">< p = x * 2^p for p = 0 .. 16 extern uint16_t shiftu16(uint16_t x, int16_t p); // 8. return x * 2^p for p = - 16 .. 16 extern int8_t shifts8(int8_t x, int8_t p); // 9. return x * 2^p for p = -8 .. 8 extern bool isequals16(int16_t x, int16_t y); // 10. returns 1 if x == y, 0 if x != y extern bool isequalu32(uint32_t x, uint32_t y); // 11. returns 1 if x == y, 0 if x != y int main(void) { uint32_t a = 4000000000; uint32_t b = 3000000000; printf("question 1, add64: correct answer = %lld\n", 7000000000); printf("question 1, add64: student answer = %lld\n\n", add64(a, b)); uint64_t c = 9000000000; uint64_t d = 8000000000; printf("question 2, sub64: correct answer = %lld\n", c - d); printf("question 2, sub64: student answer = %lld\n\n", sub64(c, d)); int16_t e = 254; int16_t f = 4; printf("question 3, mins16, test 1: correct answer = %hd\n", f); printf("question 3, mins16, test 1: student answer = %hd\n\n", mins16(e, f)); printf("question 3, mins16, test 2: correct answer = %hd\n", f); printf("question 3, mins16, test 2: student answer = %hd\n\n", mins16(f, e)); uint8_t g = 8; uint8_t h = 42; printf("question 4, minu8, test 1: correct answer = %hhu\n", g); printf("question 4, minu8, test 1: student answer = %hhu\n\n", minu8(g, h)); printf("question 4, minu8, test 2: correct answer = %hhu\n", g); printf("question 4, minu8, test 2: student answer = %hhu\n\n", minu8(h, g)); uint32_t i = 32; uint32_t j = 16; printf("question 5, islessthanu32, test 1: correct answer = %u\n", 0); printf("question 5, islessthanu32, test 1: student answer = %u\n\n", islessthanu32(i, j)); printf("question 5, islessthanu32, test 2: correct answer = %u\n", 1); printf("question 5, islessthanu32, test 2: student answer = %u\n\n", islessthanu32(j, i)); int8_t k = -3; int8_t l = 2; printf("question 6, islessthans8, test 1: correct answer = %hhd\n", 1); printf("question 6, islessthans8, test 1: student answer = %hhd\n\n", islessthans8(k, l)); printf("question 6, islessthans8, test 2: correct answer = %hhd\n", 0); printf("question 6, islessthans8, test 2: student answer = %hhd\n\n", islessthans8(l, k)); uint16_t m = 3; uint16_t n = 4; printf("question 7, shiftleftu16: correct answer = %hu\n", 48); printf("question 7, shiftleftu16: student answer = %hu\n\n", shiftleftu16(m, n)); uint16_t m_a = 8; uint16_t n_a = 12; printf("question 8, shiftu16, test 1: correct answer = %hu\n", 32768); printf("question 8, shiftu16, test 1: student answer = %hu\n\n", shiftu16(m_a, n_a)); printf("question 8, shiftu16, test 2: correct answer = %hu\n", 2); printf("question 8, shiftu16, test 2: student answer = %hu\n\n", shiftu16(m_a, -2)); int8_t o = -4; int8_t p = 4; printf("question 9, shifts8, test 1: correct answer = %hhd\n", -64); printf("question 9, shifts8, test 1: student answer = %hhd\n\n", shifts8(o, p)); printf("question 9, shifts8, test 2: correct answer = %hhd\n", -2); printf("question 9, shifts8, test 2: student answer = %hhd\n\n", shifts8(o, - 1)); int16_t q = -32; int16_t r = 16; printf("question 10, isequals16, test 1: correct answer = %hd\n", 0); printf("question 10, isequals16, test 1: student answer = %hd\n\n", isequals16(q, r)); printf("question 10, isequals16, test 2: correct answer = %hd\n", 1); printf("question 10, isequals16, test 2: student answer = %hd\n\n", isequals16(q, q)); uint32_t s = 32; uint32_t t = 16; printf("question 11, isequalu32, test 1: correct answer = %u\n", 0); printf("question 11, isequalu32, test 1: student answer = %u\n\n", isequalu32(s, t)); printf("question 11, isequalu32, test 2: correct answer = %u\n", 1); printf("question 11, isequalu32, test 2: student answer = %u\n\n", isequalu32(s, s)); return exit_success; } .global sum .text @ uint16_t sum(uint16_t x[], uint16_t count); @ r0r0r1 sum: mov r2, r0 mov r0, #0 sum_loop: ldr r3, [r2], #4 add r0, r0, r3 subs r1, r1, #1 @ i-- bne sum_loop bx lr .global fourvariable .text @ f = (g + h) - (i + j); @ int32_t fourvariable(int32_t g, int32_t h, int32_t i, int32_t j); @ r0r0r1r2r3 fourvariable: add r0, r0, r1 @ r0 = g + h add r1, r2, r3 @ r1 = i + j sub r0, r0, r1 @ we must return our result in r0 bx lr p="x" *="" 2^p="" for="" p="0" ..="" 16="" extern="" uint16_t="" shiftu16(uint16_t="" x,="" int16_t="" p);="" 8.="" return="" x="" *="" 2^p="" for="" p="-" 16="" ..="" 16="" extern="" int8_t="" shifts8(int8_t="" x,="" int8_t="" p);="" 9.="" return="" x="" *="" 2^p="" for="" p="-8" ..="" 8="" extern="" bool="" isequals16(int16_t="" x,="" int16_t="" y);="" 10.="" returns="" 1="" if="" x="=" y,="" 0="" if="" x="" !="y" extern="" bool="" isequalu32(uint32_t="" x,="" uint32_t="" y);="" 11.="" returns="" 1="" if="" x="=" y,="" 0="" if="" x="" !="y" int="" main(void)="" {="" uint32_t="" a="4000000000;" uint32_t="" b="3000000000;" printf("question="" 1,="" add64:="" correct="" answer="%lld\n"," 7000000000);="" printf("question="" 1,="" add64:="" student="" answer="%lld\n\n"," add64(a,="" b));="" uint64_t="" c="9000000000;" uint64_t="" d="8000000000;" printf("question="" 2,="" sub64:="" correct="" answer="%lld\n"," c="" -="" d);="" printf("question="" 2,="" sub64:="" student="" answer="%lld\n\n"," sub64(c,="" d));="" int16_t="" e="254;" int16_t="" f="4;" printf("question="" 3,="" mins16,="" test="" 1:="" correct="" answer="%hd\n"," f);="" printf("question="" 3,="" mins16,="" test="" 1:="" student="" answer="%hd\n\n"," mins16(e,="" f));="" printf("question="" 3,="" mins16,="" test="" 2:="" correct="" answer="%hd\n"," f);="" printf("question="" 3,="" mins16,="" test="" 2:="" student="" answer="%hd\n\n"," mins16(f,="" e));="" uint8_t="" g="8;" uint8_t="" h="42;" printf("question="" 4,="" minu8,="" test="" 1:="" correct="" answer="%hhu\n"," g);="" printf("question="" 4,="" minu8,="" test="" 1:="" student="" answer="%hhu\n\n"," minu8(g,="" h));="" printf("question="" 4,="" minu8,="" test="" 2:="" correct="" answer="%hhu\n"," g);="" printf("question="" 4,="" minu8,="" test="" 2:="" student="" answer="%hhu\n\n"," minu8(h,="" g));="" uint32_t="" i="32;" uint32_t="" j="16;" printf("question="" 5,="" islessthanu32,="" test="" 1:="" correct="" answer="%u\n"," 0);="" printf("question="" 5,="" islessthanu32,="" test="" 1:="" student="" answer="%u\n\n"," islessthanu32(i,="" j));="" printf("question="" 5,="" islessthanu32,="" test="" 2:="" correct="" answer="%u\n"," 1);="" printf("question="" 5,="" islessthanu32,="" test="" 2:="" student="" answer="%u\n\n"," islessthanu32(j,="" i));="" int8_t="" k="-3;" int8_t="" l="2;" printf("question="" 6,="" islessthans8,="" test="" 1:="" correct="" answer="%hhd\n"," 1);="" printf("question="" 6,="" islessthans8,="" test="" 1:="" student="" answer="%hhd\n\n"," islessthans8(k,="" l));="" printf("question="" 6,="" islessthans8,="" test="" 2:="" correct="" answer="%hhd\n"," 0);="" printf("question="" 6,="" islessthans8,="" test="" 2:="" student="" answer="%hhd\n\n"," islessthans8(l,="" k));="" uint16_t="" m="3;" uint16_t="" n="4;" printf("question="" 7,="" shiftleftu16:="" correct="" answer="%hu\n"," 48);="" printf("question="" 7,="" shiftleftu16:="" student="" answer="%hu\n\n"," shiftleftu16(m,="" n));="" uint16_t="" m_a="8;" uint16_t="" n_a="12;" printf("question="" 8,="" shiftu16,="" test="" 1:="" correct="" answer="%hu\n"," 32768);="" printf("question="" 8,="" shiftu16,="" test="" 1:="" student="" answer="%hu\n\n"," shiftu16(m_a,="" n_a));="" printf("question="" 8,="" shiftu16,="" test="" 2:="" correct="" answer="%hu\n"," 2);="" printf("question="" 8,="" shiftu16,="" test="" 2:="" student="" answer="%hu\n\n"," shiftu16(m_a,="" -2));="" int8_t="" o="-4;" int8_t="" p="4;" printf("question="" 9,="" shifts8,="" test="" 1:="" correct="" answer="%hhd\n"," -64);="" printf("question="" 9,="" shifts8,="" test="" 1:="" student="" answer="%hhd\n\n"," shifts8(o,="" p));="" printf("question="" 9,="" shifts8,="" test="" 2:="" correct="" answer="%hhd\n"," -2);="" printf("question="" 9,="" shifts8,="" test="" 2:="" student="" answer="%hhd\n\n"," shifts8(o,="" -="" 1));="" int16_t="" q="-32;" int16_t="" r="16;" printf("question="" 10,="" isequals16,="" test="" 1:="" correct="" answer="%hd\n"," 0);="" printf("question="" 10,="" isequals16,="" test="" 1:="" student="" answer="%hd\n\n"," isequals16(q,="" r));="" printf("question="" 10,="" isequals16,="" test="" 2:="" correct="" answer="%hd\n"," 1);="" printf("question="" 10,="" isequals16,="" test="" 2:="" student="" answer="%hd\n\n"," isequals16(q,="" q));="" uint32_t="" s="32;" uint32_t="" t="16;" printf("question="" 11,="" isequalu32,="" test="" 1:="" correct="" answer="%u\n"," 0);="" printf("question="" 11,="" isequalu32,="" test="" 1:="" student="" answer="%u\n\n"," isequalu32(s,="" t));="" printf("question="" 11,="" isequalu32,="" test="" 2:="" correct="" answer="%u\n"," 1);="" printf("question="" 11,="" isequalu32,="" test="" 2:="" student="" answer="%u\n\n"," isequalu32(s,="" s));="" return="" exit_success;="" }="" .global="" sum="" .text="" @="" uint16_t="" sum(uint16_t="" x[],="" uint16_t="" count);="" @="" r0="" r0="" r1="" sum:="" mov="" r2,="" r0="" mov="" r0,="" #0="" sum_loop:="" ldr="" r3,="" [r2],="" #4="" add="" r0,="" r0,="" r3="" subs="" r1,="" r1,="" #1="" @="" i--="" bne="" sum_loop="" bx="" lr="" .global="" fourvariable="" .text="" @="" f="(g" +="" h)="" -="" (i="" +="" j);="" @="" int32_t="" fourvariable(int32_t="" g,="" int32_t="" h,="" int32_t="" i,="" int32_t="" j);="" @="" r0="" r0="" r1="" r2="" r3="" fourvariable:="" add="" r0,="" r0,="" r1="" @="" r0="g" +="" h="" add="" r1,="" r2,="" r3="" @="" r1="i" +="" j="" sub="" r0,="" r0,="" r1="" @="" we="" must="" return="" our="" result="" in="" r0="" bx=""> p = x * 2^p for p = 0 .. 16 extern uint16_t shiftu16(uint16_t x, int16_t p); // 8. return x * 2^p for p = - 16 .. 16 extern int8_t shifts8(int8_t x, int8_t p); // 9. return x * 2^p for p = -8 .. 8 extern bool isequals16(int16_t x, int16_t y); // 10. returns 1 if x == y, 0 if x != y extern bool isequalu32(uint32_t x, uint32_t y); // 11. returns 1 if x == y, 0 if x != y int main(void) { uint32_t a = 4000000000; uint32_t b = 3000000000; printf("question 1, add64: correct answer = %lld\n", 7000000000); printf("question 1, add64: student answer = %lld\n\n", add64(a, b)); uint64_t c = 9000000000; uint64_t d = 8000000000; printf("question 2, sub64: correct answer = %lld\n", c - d); printf("question 2, sub64: student answer = %lld\n\n", sub64(c, d)); int16_t e = 254; int16_t f = 4; printf("question 3, mins16, test 1: correct answer = %hd\n", f); printf("question 3, mins16, test 1: student answer = %hd\n\n", mins16(e, f)); printf("question 3, mins16, test 2: correct answer = %hd\n", f); printf("question 3, mins16, test 2: student answer = %hd\n\n", mins16(f, e)); uint8_t g = 8; uint8_t h = 42; printf("question 4, minu8, test 1: correct answer = %hhu\n", g); printf("question 4, minu8, test 1: student answer = %hhu\n\n", minu8(g, h)); printf("question 4, minu8, test 2: correct answer = %hhu\n", g); printf("question 4, minu8, test 2: student answer = %hhu\n\n", minu8(h, g)); uint32_t i = 32; uint32_t j = 16; printf("question 5, islessthanu32, test 1: correct answer = %u\n", 0); printf("question 5, islessthanu32, test 1: student answer = %u\n\n", islessthanu32(i, j)); printf("question 5, islessthanu32, test 2: correct answer = %u\n", 1); printf("question 5, islessthanu32, test 2: student answer = %u\n\n", islessthanu32(j, i)); int8_t k = -3; int8_t l = 2; printf("question 6, islessthans8, test 1: correct answer = %hhd\n", 1); printf("question 6, islessthans8, test 1: student answer = %hhd\n\n", islessthans8(k, l)); printf("question 6, islessthans8, test 2: correct answer = %hhd\n", 0); printf("question 6, islessthans8, test 2: student answer = %hhd\n\n", islessthans8(l, k)); uint16_t m = 3; uint16_t n = 4; printf("question 7, shiftleftu16: correct answer = %hu\n", 48); printf("question 7, shiftleftu16: student answer = %hu\n\n", shiftleftu16(m, n)); uint16_t m_a = 8; uint16_t n_a = 12; printf("question 8, shiftu16, test 1: correct answer = %hu\n", 32768); printf("question 8, shiftu16, test 1: student answer = %hu\n\n", shiftu16(m_a, n_a)); printf("question 8, shiftu16, test 2: correct answer = %hu\n", 2); printf("question 8, shiftu16, test 2: student answer = %hu\n\n", shiftu16(m_a, -2)); int8_t o = -4; int8_t p = 4; printf("question 9, shifts8, test 1: correct answer = %hhd\n", -64); printf("question 9, shifts8, test 1: student answer = %hhd\n\n", shifts8(o, p)); printf("question 9, shifts8, test 2: correct answer = %hhd\n", -2); printf("question 9, shifts8, test 2: student answer = %hhd\n\n", shifts8(o, - 1)); int16_t q = -32; int16_t r = 16; printf("question 10, isequals16, test 1: correct answer = %hd\n", 0); printf("question 10, isequals16, test 1: student answer = %hd\n\n", isequals16(q, r)); printf("question 10, isequals16, test 2: correct answer = %hd\n", 1); printf("question 10, isequals16, test 2: student answer = %hd\n\n", isequals16(q, q)); uint32_t s = 32; uint32_t t = 16; printf("question 11, isequalu32, test 1: correct answer = %u\n", 0); printf("question 11, isequalu32, test 1: student answer = %u\n\n", isequalu32(s, t)); printf("question 11, isequalu32, test 2: correct answer = %u\n", 1); printf("question 11, isequalu32, test 2: student answer = %u\n\n", isequalu32(s, s)); return exit_success; } .global sum .text @ uint16_t sum(uint16_t x[], uint16_t count); @ r0r0r1 sum: mov r2, r0 mov r0, #0 sum_loop: ldr r3, [r2], #4 add r0, r0, r3 subs r1, r1, #1 @ i-- bne sum_loop bx lr .global fourvariable .text @ f = (g + h) - (i + j); @ int32_t fourvariable(int32_t g, int32_t h, int32_t i, int32_t j); @ r0r0r1r2r3 fourvariable: add r0, r0, r1 @ r0 = g + h add r1, r2, r3 @ r1 = i + j sub r0, r0, r1 @ we must return our result in r0 bx lr>