ZX Spectrum "Hello World"
Displaying "Hello World" to the top of the screen... there are several ways to do this...
In this example the CALL 8252 routine is used to display each character of our string. The routine also starts to deduct the value of BC register pairs, and completed when BC register pair equal to 0. Therefore we must load the BC register pair also with the length of our string before the routine starts.
main ;Declare MAIN section of code (good habit).
ld a, 2 ;Load Accumulator with 2.
call 5633 ;Open channel 2 (top part of screen).
call 5633 ;Open channel 2 (top part of screen).
ld DE, string ;load DE register pair with string values.
ld BC, 11 ;Load BC (Bit-Counter) with 11.
call 8252 ;Routine displays each character,
call 8252 ;Routine displays each character,
;deducts from BC until reaches 0.
string
defb "HELLO WORLD" ;Assembler will load each character
defb "HELLO WORLD" ;Assembler will load each character
;into the memory according to ZX character map
ret ;return (to basic)
Let's take it a step further by defining position, color, flashing and brightness attributes...
Also, we can have the assembler count the length of our string.
org 33000
main
ld a, 2 ;Load Accumulator with 2
call 5633 ;open channel 2 (top part of screen)
ld DE,string ;load DE register pair with string values
ld BC,EOFstring-string ;Load BC (BitCounter) with string length
call 8252 ;routine to display each character until BC=0
ret ;return to basic
; attribute type and their values
string
defb 16,4 ;Ink color(0-7)
defb 17,1 ;Paper color (0-7)
defb 18,1 ;Flash? (0 or 1)
defb 19,1 ;Bright? (0 or 1)
defb 20,0 ;Inverse color attributes (0 or 1)
defb 21,1 ;Over (0 or 1) - characters overlap
defb 22,6,7 ;"22" = AT, then x, y coordinates
defb "HELLO WORLD"
EOFstring EQU $ ;EndOFstring, detect number of Characters in string


Comments
Post a Comment