Page 1 of 1

Assembly Beginner

Posted: Wed Nov 21, 2018 11:57 pm
by htheus1974
Hey there! I am new to this forum.
I am interested to learn assembly on a C64. I am using C64Studio and the VICE Emulater for that. I worte today two codefragments:

*=$0801
!byte $0c,$08,$e2,$07,$9e,$20,$32,$30,$36,$32,$00,$00,$00

lda #$41
ldx #$ff

loop
sta $03ff,x
dex
bne loop
rts


and a smaller one

*=$C000

lda #$01
sta $0400
lda #$00
sta $d800

lda #$02
sta $0401
lda #$04
sta $d801

rts


So my questions are:
1) The first program compiles and runs AT ONCE with autostart option "inject into RAM" in VICE. But its not running if i change the startaddress for example to $C000 and try to run it in vice with sys 49152. Well the program run only if the first line is saved in $0801. Is there anything special about
$0801 (Begin of Basic RAM) as i should know for assembly?

2) The second program runs perfectly (but NOT automatically) with any address expect $0801. I realy dont understand why ... May be you have a hint for me ?

Thank you very much in advance for your answer and i am sorry about my bad english knowledge :-)
Greetings from Zurich, Switzerland.

Han

Re: Assembly Beginner

Posted: Sat Nov 24, 2018 11:33 pm
by TMR
htheus1974 wrote: Wed Nov 21, 2018 11:57 pm 1) The first program compiles and runs AT ONCE with autostart option "inject into RAM" in VICE. But its not running if i change the startaddress for example to $C000 and try to run it in vice with sys 49152. Well the program run only if the first line is saved in $0801. Is there anything special about $0801 (Begin of Basic RAM) as i should know for assembly?
The first !byte statement after the *=$0801 is essentially a small BASIC program being pushed into memory as hex; specifically it says 2018 SYS 2062 so, when you inject or drag/drop that assembled program into VICE, the BASIC runs and executes your code at 2062 ($080e in hex) which is where that first LDA after the !byte sits in memory. If you change the start address it's no longer loading into BASIC; forcing it up to $c000 gets you 13 bytes of unexecutable data (what was the BASIC program) followed by the actual code so SYS49152+13 should work.
htheus1974 wrote: Wed Nov 21, 2018 11:57 pm 2) The second program runs perfectly (but NOT automatically) with any address expect $0801. I realy dont understand why ... May be you have a hint for me ?
The second program at $c000 is just raw machine code, without the BASIC startline like the one included by the !byte command in the first listing it can only be started manually with a SYS command. If you assemble at $0801 it'll cause problems because BASIC is trying to treat it as a BASIC program and finding something it doesn't understand.

My variation of the BASIC startline builder looks like this:

Code: Select all

; Add a BASIC startline
		* = $0801
		!word entry-2
		!byte $00,$00,$9e
		!text "2066"
		!byte $00,$00,$00

; Entry point at $0812
		* = $0812
entry		lda #$00
		sta $d020
The first * aims at the start of BASIC and the !word, !byte and !text commands construct a BASIC listing which reads 0 SYS 2066 and that's where the code starts assembing from the second origin point, the * = $0812 - if you change the 2066 to 16384 and the $0812 to $4000 it'll move the machine code up memory but should still execute automatically.