Friday, 20 December 2013

You should be familiar with c-strings from C or C++. They are simply a sequence of characters terminated with a null character ( x00). The LC-3 pseudo-op .STRINGZ takes a text string as a parameter and builds a c-string: label .STRINGZ "Hello world!" ;you're probably sick of "hello world" by now ... ; so make your own message! This pseudo-op stores the characters of the string, one per memory location, starting with the location "label". A null (x00) is written to the memory location following the last character. The TRAP x22 instruction will take the contents of R0 to be the starting address of a c-string, and output each character of the string until it hits the null. Write code that creates a message using .STRINGZ and outputs it to the screen using TRAP x22. Examine the memory locations starting with "label" to make sure you understand how the assembler has set up the string.

    .ORIG x3000
    LEA R0,Label    ; load array base addr in R3
    TRAP x22    ; output from address in R2 untill it gets x0000 (null)
    HALT
Label    .STRINGZ "Hello World!"    ; create string array in memory
    .END

No comments:

Post a Comment