TweeZcodeCompiler / twee_zcode_compiler

compiler project at FU Berlin
MIT License
3 stars 0 forks source link

Static Strings #91

Closed Philip-The-Developer closed 9 years ago

Philip-The-Developer commented 9 years ago

You can now create static strings in your Dynamic Memory with:

.STRING <name> "<string>"

Moreover you can print your string with the oppcode:

print_addr <name>

Or you can pass the adress of your string to a variable with:

point <variable> <name>

Have fun ☀

ottne commented 9 years ago

Why is point needed?

Philip-The-Developer commented 9 years ago

You need point, if you want to return strings from a routine; like:

.STRING test "Hallo Welt"

.FUNCT main aString
call getMyFantasticString -> aString
print_addr aString
new_line
quit

.FUNCT getMyFantasticString myString
point myString test
ret myString
ottne commented 9 years ago

We have store for that purpose.

store myString test

And why not just return the adress by value?

.FUNCT getMyFantasticString myString
ret test
Philip-The-Developer commented 9 years ago

Yestarday evening I my opinon was, that store stores the value at an adress instead of the adress themselfe. But today (after an intensive thinking session) I think, that the directives could interprete as variables which contains a byte-adress. I will implement that fact today in the routine generator, with the result that every opcode, which can use Variables, also will usable with directives. In a nutshell you get your functionallity for store and ret.

ottne commented 9 years ago

Directives should create an address for a name. That name can then be used elsewhere in the assembly, but is replaced with the address constant that the assembler creates.

For example, if I declare a .STRING foo = "foo" and the assembler generates address 0xF00 for the string, then print_addr foo should be translated the same as print_addr 0xF00 would.

You don't even need any typechecking. When someone decides to print_addr a byte-array or to perform a storeb on a string, then that's the programmers fault.