12

This is probably an easy one, but I'm stumped.

I want to run this ZX Spectrum Hello World routine on my Sinclair ZX Spectrum 48k.

I'm going to describe all the steps I took so it's easier to see where the problem lies.

1) I didn't change the default RAMTOP, so I started my routine at 65415.

2) I translated the hex codes into decimal like so:

ld   a, 2                ; 3E 02 ; => 62 2
call CHAN_OPEN           ; CD 01 16; => 205 1 22
ld   de, text            ; 11 0E 7F; => 17 14 127
ld   bc, textend-text    ; 01 0E 00; => 1 14 0
jp   PRINT               ; C3 3C 20; => 195 60 32

defb 'Hello, World!'     ; 48 65 6C 6C 6F 2C 20 57
                                 ; 6F 72 6C 64 21; => 72 101 108 108 111 44 32 87 111 114 108 100 33
defb 13                  ; 0D; => 13

3) I wrote a short basic program to put the code into memory:

10 FOR I=65415 TO 65535
20 PRINT I,
30 INPUT C
40 POKE I,C
50 PRINT C,
60 NEXT I

4) And one to check it was in place

10 FOR I=65415 TO 65535
20 PRINT I, PEEK(I),
30 NEXT I

5) I ran it with

RANDOMIZE USR 65415

The good news is that the routine ran & exited, but instead of "Hello, World!", it printed ?????????????

6) For debugging I checked my hex to decimal calculations and made sure I hadn't missed anything. I also checked the character codes for the alphabet letters in the user manual.

So my question is: Why did this not produce "Hello, World!" printed to screen as desired?

20

It may help if you load the address of the text to be printed. After all, you relocated the routine including the text, but still load the old address:

ld   de, text            ; 11 0E 7F; => 17 14 127

7F0Eh equals 32,526, which is fine with the orriginal address of 32,512.

With 65,415 as start address, DE should now be loaded with 65,429, or FF95h, as in

ld   de, text            ; 11 95 FF; => 17 149 255
1
  • 1
    Thanks for going the extra mile and calculating the new address for me - it now works as expected! – harlandski Dec 28 '19 at 13:42
7

The DE register point to text address in memory, and they are based on the example, so they still point to the old address. You should change them to point to text in new address. If I did the math right, the line should be 11 95 FF in hex.

4

The hex codes are OK, but it is compiled for using from address 7F00h (32512). You have two options:

Option 1 - change the address:

Add line

5 CLEAR 32511

Change line 10 to:

10 FOR I=32512 TO 32767

Input your numbers and use RANDOMIZE USR 32512

Option 2 - change the routine itself as "Raffzahn" described. (17 14 127 change to 17 149 255)

2
  • 1
    Thank you. I now see that this is the meaning of "org 32512" in the source code. – harlandski Dec 29 '19 at 16:54
  • 1
    ORG means "origin", i.e. "the memory address where the next instruction will be stored". (Establishes the origin position where to place generated code. Several ORG directives can be used in the same program.) – Martin Maly Dec 29 '19 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.