Omnimaga
Calculator Community => Casio Calculators => Topic started by: Eiyeron on March 09, 2014, 07:48:29 am
-
HI guys, I'm trying to learn ASM and I have a little problem : It I get a TLB eror when the program seems to access to LTORG content.
I'm using Macro AS (http://john.ccac.rwth-aachen.de:8000/as/) because I'm getting fed with FX SDK, and here is the source code I did :
CPU SH7700
LISTING ON
SEGMENT code
;Syscall macro
syscall macro op
MOV.L op, R0;
MOV.L scall_table, R2;
JMP @R2
NOP
endm
main:
;STS.L PR,@-R15; I got this idea when reading FX SDK listings.
MOV.W #5, R4; Trying to give as argument id = 5 to DisplayErrorMessage
syscall scall_DislayErrorMessage; Should print an error message
NOP
; Stop? I don't really know how to stop that.
;LDS.L @R15+,PR
MOV #1, R0
RTS
NOP; By here it should have stopped
LTORG; But he goes on further
;Data
; It doens't accept SEGMENT DATA
String dc.B "Hello World!\0"; And crashes here accroding to the listing
ALIGN 4
;syscalls
scall_Print_OS dc.L $013c
ALIGN 4
scall_DislayErrorMessage dc.L $0954
ALIGN 4
scall_table dc.L $80010070
WIth tha code, I have a TLB error with TARGET 0x12 (?) and PC = 0x1E (in the Hello world string Oo). Why?
Addendum : I chose to not use FX SDK because I don't know how to include properly ASM. Do you have any good idea/methods?
-
I chose to not use FX SDK because I don't know how to include properly ASM. Do you have any good idea/methods?
You can include any asm function in a C program when you export it with a function name _FuncName
Here is a small asm-only program:
.INCLUDE "syscall.inc"
.MACRO SC SysCall
mov.l #\SysCall, r0
mov.l #JumpTableTop, r2
jsr @r2
nop
.ENDM
.EXPORT _BR_Size
.EXPORT _AddIn_main
.SECTION P, CODE, ALIGN=4
_AddIn_main:
SC Bdisp_AllClr_VRAM
mov #5, r4 ; col
mov #3, r5 ; row
SC locate
mov.l #text, r4 ; str
mov #1, r5 ; mode
SC Print
loop:
mov.l #key, r4 ; key
SC GetKey
bra loop
nop
rts
nop
.SECTION C, DATA, ALIGN=4
text .SDATAZ "Hello, world!"
.SECTION B, DATA, ALIGN=4
_BR_Size .RES.L 1
key .RES.L 1
.END
JumpTableTop .EQU h'80010070
Print .EQU h'013C
Bdisp_AllClr_VRAM .EQU h'0143
locate .EQU h'0807
GetKey .EQU h'090F
-
Ok, how can I call C functions from an assembler file? .INCLUDE "header.h" won't work because syntax is way too different.
-
.IMPORT _FuncName should do it.
Refer to section "9.3.2 Function Calling Interface" in the SHC manual.
The SDK manuals are available as a separate download at edu.casio.com
-
Ok, how can I call C functions from an assembler file? .INCLUDE "header.h" won't work because syntax is way too different.
Well, you'll need to understand the calling (parameter passing) convention for that compiler. Then it should be straightforward. More, see wikipedia: http://en.wikipedia.org/wiki/Calling_convention (http://en.wikipedia.org/wiki/Calling_convention)
-
so, according to wikipedia:
R0..R3 are temporary variables
R4..R7 are arguments
R8..R14 are variables that must be preserved
R15 is the stack pointer
SH3's assembly looks a lot like M68K's
however, the parameter passing conventions aren't the same
page 200 of the Renesas compiler documentation (http://documentation.renesas.com/eng/products/tool/rej10b0152_sh.pdf) gives an example of the structure of a function and a function call.
-
Must be preserved, or are automatically preserved by the processor already? I think I'm getting the handle, except the fact I get a warning about an illegal displacement here
MOV.L @(2,R15), R4
and wrong mnemonic with using a macro
.MACRO FIX Rd
SHLR8 \Rd
SHLR4 \Rd
SHLL \Rd
.ENDM
...
FIX R10 ; FIX(pz) -> pz // And here goes the mnemonic error
And yipee, gotta read a cr*pload of books! yay :|
-
they must be preserved, which means that the context before a function call and after a function call must have the same values for these registers.
so basically you have to save them to the stack when you use them in a function.
-
Yeah, I thought so. Yeah, refactor.