Hi good afternoon.
how can you create plaese "sys adresse,a,b" in asm?
Thanks.
call sys in basic: sys address,a,b
- ahenry3068
- Posts: 1138
- Joined: Tue Apr 04, 2023 9:57 pm
Re: call sys in basic: sys address,a,b
I do not understand what your asking exactly.
If you mean how would you do the same thing in Assembly then it's actually really easy. SYS is a wrapper to call machine code.
So in Basic if your doing.
POKE $30C, 65
SYS CHROUT
In assembly you just
LDA #65
JSR CHROUT.
The BASIC sys has to do some other things to like Move the register back into the "Cache" Address's $30C-$30F then return to the BASIC code. In assembly you just work with the registers directly.
Re: call sys in basic: sys address,a,b
To further expand on this, "JSR" is the equivalent of "SYS". The first parameter of SYS is the address, so that is also the address with JSR. With SYS, any additional parameters that come after the address need to be pulled off using KERNAL and BASIC functions. I know how to do that on a C64/C128, but am not sure the BASIC functions are at the same addresses on the CX16. If you are calling an assembly language subroutine from another assembly language routine, you can either pass your parameters in registers, use the zero page pseudo registers, or come up with your own way of passing them like pushing them onto the hardware stack or creating a software stack. For simple subroutines I use registers or pseudo registers. If you need to call the subroutine recursively you need a stack and I generally use a software stack and leave the 6502 hardware stack alone to mostly store return addresses.
- ahenry3068
- Posts: 1138
- Joined: Tue Apr 04, 2023 9:57 pm
Re: call sys in basic: sys address,a,b
Ditto on the Psuedo registers. There's really rarely much need for any other method.mgkaiser wrote: ↑Wed Apr 24, 2024 4:42 pm To further expand on this, "JSR" is the equivalent of "SYS". The first parameter of SYS is the address, so that is also the address with JSR. With SYS, any additional parameters that come after the address need to be pulled off using KERNAL and BASIC functions. I know how to do that on a C64/C128, but am not sure the BASIC functions are at the same addresses on the CX16. If you are calling an assembly language subroutine from another assembly language routine, you can either pass your parameters in registers, use the zero page pseudo registers, or come up with your own way of passing them like pushing them onto the hardware stack or creating a software stack. For simple subroutines I use registers or pseudo registers. If you need to call the subroutine recursively you need a stack and I generally use a software stack and leave the 6502 hardware stack alone to mostly store return addresses.
Re: call sys in basic: sys address,a,b
hello, thanks for help.
what kind of registers are these?
$30C-$30F
greeting.
what kind of registers are these?
$30C-$30F
greeting.
- ahenry3068
- Posts: 1138
- Joined: Tue Apr 04, 2023 9:57 pm
Re: call sys in basic: sys address,a,b
Those are not true registers. They are 6502 Memory addresses that BASIC uses to store register Values. The following isn't exact code but BASIC does something like this when SYS is invoked.
LDA $30C LDX $30D LDY $30E LOADS THE PROCESSOR REGISTER FROM $30F ( I really don't know the instructions here) JSRS to the SYS target Does the reverse Storing the Registers to the CACHE addresss Returns to BASIC.
Re: call sys in basic: sys address,a,b
When you call a machine language routine in assembly, you simply load the necessary values in the registers and perform a JSR to the address of the routine.
When you do this from BASIC, you have no way to access the registers directly, because there are no commands to do this, and besides, BASIC is constantly using them for its own purposes. So the memory locations $30C through $30F are temporary storage locations, from which the binary code that is executed as part of the SYS command will load the registers before doing its own jump-subroutine to the address.
The location $30C is where the accumulator value will be loaded from. $30D is for the X index register. $30E is for the Y index register, and $30F is for the status register and is used for things like setting the carry bit. So what BASIC essentially does, when you issue a SYS command such as SYS $FFD2, is to run the following assembly code:
There is more detail involved than this, but this is the essential portion.
Code: Select all
LDA #$65 ;load accumulator with value $65
JSR $FFD2 ;jump-subroutine to CHROUT ($FFD2)
The location $30C is where the accumulator value will be loaded from. $30D is for the X index register. $30E is for the Y index register, and $30F is for the status register and is used for things like setting the carry bit. So what BASIC essentially does, when you issue a SYS command such as SYS $FFD2, is to run the following assembly code:
Code: Select all
LDA $030F ;load the accumulator with the value stored in $030F
;(to be placed in the status register)
PHA ;push the value of the accumulator onto the stack
LDA $030C ;load the accumulator with the value stored in $030C
LDX $030D ;load the X register with the value stored in $030D
LDY $030E ;load the Y register with the value stored in $030E
PLP ;pull the value at the top of the stack into the status register
Re: call sys in basic: sys address,a,b
Hello, thank you for the good explanation
greeting
greeting