3 ms·
>Yes, ret cannot be used outside procedures. This is again intentional. As this emulator was aimed at students and newcomers to assembly, we wanted to kind of s
by rep_lodsb 4y ago
>Yes, ret cannot be used outside procedures. This is again intentional. As this emulator was aimed at students and newcomers to assembly, we wanted to kind of safeguard from accidentally using ret outside of a procedure context.
This decision seems more likely to teach newcomers the wrong things, like expecting the following code to work:
def plus {
; add two numbers on stack, return result on stack
pop ax
pop bx
add ax,bx
push ax
ret
}
To catch errors like this, you might want to implement a "shadow stack" in the interpreter that keeps track of the type of each stack element (number or return address).
edit, some more thoughts on how to implement this:
https://news.ycombinator.com/item?id=35517012 https://news.ycombinator.com/item?id=35517012
/edit
But the most essential feature of assembly / machine language is that there is in reality no distinction between characters or numbers and memory addresses, procedures and labels, or between code and data. Even compiler-generated code often has jumps to procedures (tail-call optimization).
Also by not exposing any code addresses, your virtual machine becomes less powerful than C - how would you call a function pointer?