2018-09-09 23:08:25 +00:00
|
|
|
#
|
|
|
|
.sect .text; .sect .rom; .sect .data; .sect .bss
|
|
|
|
|
|
|
|
/* Bounds check. Traps if the value is out of range.
|
|
|
|
* Stack: ( value descriptor -- value )
|
|
|
|
*
|
|
|
|
* This ".rck" only works with 4-byte integers. The name is ".rck" and
|
|
|
|
* not ".rck4" because many back ends only do rck with the word size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
.define .rck
|
|
|
|
.rck:
|
|
|
|
lw r4, 0(sp) ! r4 = pointer to descriptor
|
|
|
|
addiu sp, sp, 4 ! leave value on stack
|
|
|
|
lw r5, 0(sp) ! r5 = value
|
|
|
|
|
2018-09-13 22:38:31 +00:00
|
|
|
lw at, 0(r4) ! at = lower bound
|
2018-09-09 23:08:25 +00:00
|
|
|
slt at, r5, at ! at = r5 < at
|
|
|
|
bne at, zero, .trap_erange
|
2018-09-13 22:38:31 +00:00
|
|
|
nop
|
2018-09-09 23:08:25 +00:00
|
|
|
|
2018-09-13 22:38:31 +00:00
|
|
|
lw at, 4(r4) ! at = upper bound
|
2018-09-09 23:08:25 +00:00
|
|
|
slt at, at, r5 ! at = at < r5
|
|
|
|
bne at, zero, .trap_erange
|
2018-09-13 22:38:31 +00:00
|
|
|
nop
|
2018-09-09 23:08:25 +00:00
|
|
|
|
|
|
|
jr ra
|
|
|
|
nop
|
|
|
|
|
|
|
|
.define .trap_erange
|
|
|
|
.trap_erange:
|
|
|
|
li r4, 1
|
|
|
|
j .trp
|
|
|
|
nop
|