I'm a little confused about how to create the return address labels for the 'call' and 'return' command.
Firstly, how do we push the return-address in call? Is it simply @[label] and then pushing that value onto the stack?
And to Goto the return address, wouldn't the argument passed in the translator be an integer, which is the wrong type when processing a Goto command?
It's a bit hard to tell, but I think you have the right idea.
What do you mean with the square brackets when you say "@[label]"? That's not a notation I recall seeing in the text, so I'm not exactly sure what you have in mind. But, yes, you create a label at the line of code that you want to return to and then that label is now associated with that address (which is just an integer) and that's what you put on the stack and, eventually, it gets put in the A register and then an unconditional jump is executed.
As for the data types, all of the data types used by this computer (and all of the language types) are all intercompatible in that at the end of the day they are all 16-bit signed integers. That was done very deliberately so that type systems and type checking could be neatly sidestepped, which is important given the course's very broad scope -- depth had to be extremely limited pretty much across the board.
Why do we need to put return address on the stack? We have a return label inserted as (RETURN) in the asm code and the callee function can jump back to it as assembler takes care of implementing where to jump back. What is the purpose of return address on the stack?
If are saving return address (instruction number on ROM) on the stack then callee can certainly use that but we don't need (RETURN) labels in that case, do we?
do what needs to be done to stack
do something something whatever
the function works
and changes stack as needed
Say you call the same function from more than one place, for instance, you call the sqrt() function from more than one place or you ask the use to input more than one thing. Each call is transferring control to the same piece of code (the function). How can the assembler generate code that knows where to transfer control back to when it returns?
thanks that makes sense. I was thinking we could use only the return address stored on the stack but in that case why do we need to inject return label. Seemed double dipping. Once I started implementation, then I understood that reason to inject label is to find out which ROM instruction number to store on stack for return address in first place.