Advertisement
JKattackk

A

Apr 2nd, 2022 (edited)
2,813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.61 KB | None | 0 0
  1. /*-----------------Students write their subroutine here--------------------*/
  2. PUSH {LR};
  3.  
  4. LDR R0,=WelcomeString; //Print welcome msg
  5. BL printf;
  6. BL cr;
  7.  
  8. LDR R0,= Prompt;       //prepare inital size prompt
  9.  
  10. prompt:
  11. BL printf;             //print prompt
  12. BL cr;
  13.  
  14. BL getstring;
  15.  
  16. PUSH {R0}
  17. BL value;              //print value
  18. BL cr;
  19. POP {R0};
  20.  
  21. CMP R0, 0x3;           //test for val<3, load prompt and branch if invalid
  22. ITT LT;
  23. LDRLT R0,= Prompt3;
  24. BLT prompt;
  25.  
  26. CMP R0,10;             //test for val>10, load prompt and branch if invalid
  27. ITT GT;
  28. LDRGT R0,= Prompt4;
  29. BGT prompt;
  30.  
  31. STR R0, [SP, 4];         //store size on stack
  32. .equ outAdd, 0x20001000; //output array address
  33. LDR R1,= outAdd;
  34. PUSH {R0-R1};             //this is just moving size and address over
  35. POP {R1-R2};              //so R0 is unnocupied / unneccessary
  36.  
  37. loop:
  38. LDR R0,= Prompt1;         //start of the loop loads main prompt
  39. CMP R1, 0x1;              //or prompt for last input
  40. IT EQ;
  41. LDREQ R0,= Prompt2;
  42. PUSH {R1-R2};
  43.  
  44. keyPrompt:          //seperate branch so I can print without loading original prompts
  45. BL printf;          //print prompt
  46. BL cr;
  47. BL getstring;
  48.  
  49. PUSH {R0};
  50. BL value;           //print value
  51. BL cr;
  52. POP {R0};
  53.  
  54. CMP R0, 0x0;        //checks for negative value
  55. IT LT;              //loads invalid prompt and branches back if invalid
  56. LDRLT R0,= Prompt5;
  57. BLT keyPrompt;
  58.  
  59. POP {R1-R2};        //output value to array
  60. STR R0, [R2], 0x4;
  61.  
  62. SUB R1, 0x1;        //subtract from size, check if all inputs have been grabbed
  63. CMP R1, 0x0;
  64. BNE loop;
  65.  
  66. POP {LR};
  67. BX LR;
  68. /*-------Code ends here ---------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement