Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. # Overwrites existing exception handler
  2. .ktext 0x80000180
  3. .set noat # tell assembler not to use $at (assembler temporary)
  4. # and hence not to complain when we do
  5. move $k0, $at # save $at in $k0
  6. # $k0 and $k1 are reserved for
  7. # OS and Exception Handling
  8. # programmer should not use them, so not saved
  9. .set at # tell assembler it may use $at again
  10.  
  11. li $a0, 0xFFFF0004 # Receiver data address (interrupt based, so don't need to check Receiver control)
  12. lw $v0, 0($a0) # Receiver data
  13. addi $t1,$0,'x'
  14. addi $t2,$0,'p'
  15. addi $t3,$0,'o'
  16. addi $t4,$0,'e'
  17. addi $t5,$0,'f'
  18. la $t6,player1win
  19. la $t7,player2win
  20. la $t8,printtabuleiro
  21. la $t9,printwinsandpoints
  22. #lb $t1,0($t0) #x
  23. #lb $t2,4($t0) #p
  24. #lb $t3,8($t0) #o
  25. #lb $t4,12($t0) #e
  26. #lb $t5,16($t0) #f
  27.  
  28. loopx: bne $t1,$v0,loopp #primeiro vencedor ganha
  29. jalr $t6
  30. loopp: bne $t2,$v0,loopo #estado atual do tabuleiro
  31. jalr $t8
  32. loopo: bne $t3,$v0,loope #segundo vencedor ganha
  33. jalr $t7
  34. loope: bne $t4,$v0,loopf #numero de partidas ganhas
  35. jalr $t9
  36. loopf: bne $t5,$v0,loop6 #finalizar programa
  37. li $v0,10
  38. syscall
  39. loop6: li $v0,10
  40. syscall
  41.  
  42. eret # return from exception, PC <- EPC
  43.  
  44. .text
  45. .globl main
  46. main:
  47. li $a0, 0xFFFF0000 # Receiver control
  48. lw $t0, 0($a0)
  49. ori $t0, 0x02 # set bit 1 to enable input interrupts
  50. # such a-synchronous I/O (handling of keyboard input in this case)
  51. # this is much more efficient than the "polling" we use for output
  52. # In particular, it does not "block" the main program in case there is no input
  53. sw $t0, 0($a0) # update Receiver control
  54.  
  55. mfc0 $t0, $12 # load coprocessor0 Status register
  56. ori $t0, 0x01 # set interrupt enable bit
  57.  
  58. forever:
  59.  
  60. j forever
  61. player1:
  62. #Imprime a label player1_msg
  63. li $v0,4
  64. la $a0,player1_msg
  65. syscall
  66. li $v0,5 #Scan da posição
  67. syscall
  68. addi $v0,$v0,-1 #remove 1, para poder ser de 1-9 e não de 0-8(input mais intuitivo)
  69. mul $t0,$v0,4 #multiplica por 4 por causa da memora c inteiros saltar de 4 em 4
  70. move $a0,$v0
  71. jal posicaovalida
  72. beq $v0,0,posinvalidap1
  73. li $t1,1 #t1=1=>x
  74. sw $t1, tabuleiro($t0) #guarda na posição obtida do output
  75. jal printtabuleiro
  76. j player2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement