|
18 | 18 |
|
19 | 19 | # push register to top of stack and move DSP |
20 | 20 | .macro PUSH reg |
21 | | - sw \reg, -CELL(sp) # store the value in the register to the top of the DSP |
22 | | - addi sp, sp, -CELL # move the DSP down by 1 cell |
23 | | -.endm |
| 21 | + li t0, RSP_TOP+CELL # load address of bottom of stack + 1 CELL |
| 22 | + blt sp, t0, err_overflow # jump to error handler if stack overflow |
24 | 23 |
|
25 | | -# push variable to top of stack |
26 | | -.macro PUSHVAR var |
27 | | - li t0, \var # load variable into temporary |
28 | | - sw t0, -CELL(sp) # store the variable value to the top of the DSP |
| 24 | + sw \reg, -CELL(sp) # store the value in the register to the top of the DSP |
29 | 25 | addi sp, sp, -CELL # move the DSP down by 1 cell |
30 | 26 | .endm |
31 | 27 |
|
32 | 28 | # push register to return stack |
33 | 29 | .macro PUSHRSP reg |
| 30 | + li t0, TIB_TOP+CELL # load address of bottom of stack + 1 CELL |
| 31 | + blt s2, t0, err_overflow # jump to error handler if stack overflow |
| 32 | + |
34 | 33 | sw \reg, -CELL(s2) # store value from register into RSP |
35 | 34 | addi s2, s2, -CELL # decrement RSP by 1 cell |
36 | 35 | .endm |
37 | 36 |
|
38 | 37 | # pop top of return stack to register |
39 | 38 | .macro POPRSP reg |
| 39 | + li t0, RSP_TOP # load address of top of RSP |
| 40 | + bge s2, t0, err_underflow # jump to error handler if stack underflow |
| 41 | + |
40 | 42 | lw \reg, 0(s2) # load value from RSP into register |
41 | 43 | addi s2, s2, CELL # increment RSP by 1 cell |
42 | 44 | .endm |
|
67 | 69 | li t0, \char # load character into temporary |
68 | 70 | beq a0, t0, \dest # jump to the destination if the char matches |
69 | 71 | .endm |
| 72 | + |
| 73 | +# print a message |
| 74 | +.macro print_error name, size, jump |
| 75 | + .balign CELL |
| 76 | + err_\name : |
| 77 | + la a1, msg_\name # load string message |
| 78 | + addi a2, a1, \size # load string length |
| 79 | + call uart_print # call uart print function |
| 80 | + j \jump # jump when print returns |
| 81 | +.endm |
| 82 | + |
| 83 | +# restore HERE and LATEST variables |
| 84 | +.macro restorevars reg |
| 85 | + # update HERE |
| 86 | + li t0, HERE # load HERE variable into temporary |
| 87 | + sw \reg, 0(t0) # store the address of LATEST back into HERE |
| 88 | + |
| 89 | + # update LATEST |
| 90 | + li t0, LATEST # load LATEST variable into temporary |
| 91 | + lw t1, 0(\reg) # load LATEST variable value into temporary |
| 92 | + sw t1, 0(t0) # store LATEST word into LATEST variable |
| 93 | +.endm |
| 94 | + |
| 95 | +# check for stack underflow |
| 96 | +.macro checkunderflow stacktop |
| 97 | + li t0, DSP_TOP-\stacktop # load address of top of stack |
| 98 | + bge sp, t0, err_underflow # jump to error handler if stack underflow |
| 99 | +.endm |
0 commit comments