Advertisement
STANAANDREY

factorial of array risc asm

Oct 21st, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         BRA main
  2. main    INP R0 //n
  3.         INP R1 //m
  4.         MOV R5, R1 //start
  5.         JMS readArr
  6.         MOV R1, R5
  7.         JMS printArr
  8.         HLT
  9. readArr MOV R2, #0 //i
  10. loopRead CMP R2, R0
  11.         BEQ doneRead
  12.         INP R4
  13.         STR R4, [R1]
  14.         ADD R1, #1
  15.         ADD R2, #1
  16.         BRA loopRead
  17. doneRead RET
  18. printArr PSH {LR} // Save link register
  19.         MOV R2, #0
  20.         MOV R3, R1 // Store the start of the array in R3
  21. loopPrint CMP R2, R0
  22.         BEQ donePrint
  23.         LDR R4, [R3]
  24.         JMS doFact
  25.         OUT R4
  26.         ADD R3, #1 // Move to the next element in the array
  27.         ADD R2, #1
  28.         BRA loopPrint
  29. donePrint POP {PC}
  30. doFact  MOV R6, #1
  31.         MOV R7, R4
  32. loopFact CMP R6, R4
  33.         BEQ doneFact
  34.         MUL R7, R6
  35.         ADD R6, #1
  36.         BRA loopFact
  37. doneFact MOV R4, R7
  38.         RET
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement