Guest User

Untitled

a guest
Apr 26th, 2019
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.  
  3. ReadBuffer: .space 80
  4. ReadPar: .word 0, ReadBuffer, 80
  5.  
  6. PrintfPar: .space 4
  7.  
  8. SaveR2: .space 4
  9. SaveR3: .space 4
  10. SaveR4: .space 4
  11. SaveR5: .space 4
  12.  
  13. napis: .asciiz "Wprowadz 1 liczbe calkowita (moze byc ze znakiem) = "
  14. .align 2
  15.  
  16. .text
  17.  
  18. .global czytaj
  19. czytaj:
  20. ;*** save register contents
  21. sw SaveR2,r2
  22. sw SaveR3,r3
  23. sw SaveR4,r4
  24. sw SaveR5,r5
  25.  
  26. addi r1, r0, napis
  27. sw PrintfPar,r1
  28. addi r14,r0,PrintfPar
  29. trap 5
  30.  
  31. ;*** call Trap-3 to read line
  32. addi r14,r0,ReadPar
  33. trap 3
  34.  
  35. ;*** determine value
  36. addi r2,r0,ReadBuffer
  37. addi r1,r0,0
  38. addi r4,r0,10 ;Decimal system
  39.  
  40. Loop: ;*** reads digits to end of line
  41. lbu r3,0(r2)
  42. seqi r5,r3,10 ;LF -> Exit
  43. bnez r5,Finish
  44. subi r3,r3,48 ;´0´
  45. multu r1,r1,r4 ;Shift decimal
  46. add r1,r1,r3
  47. addi r2,r2,1 ;increment pointer
  48. j Loop
  49.  
  50. Finish: ;*** restore old register contents
  51. lw r2,SaveR2
  52. lw r3,SaveR3
  53. lw r4,SaveR4
  54. lw r5,SaveR5
  55. jr r31 ; Return
RAW Paste Data