IN THE KNOW
Go to bottomPage: 1
TOPIC:
#1012
Calling Assembly code from C 11 Months ago Karma: 1
Hi,
I want to call a procedure written in assembly language from C code. In this regard I downloaded the document www.zilog.com/docs/appnotes/an0333.pdf from Zilog website. On page 5 of this document its mentioned that "The arguments are placed on the stack and their offsets from the Stack Pointer (SP) at the
entry point of an assembly function are:
arga: -3(SP)
argb: -6(SP)
argc: -12(SP)
argd: -15(SP)
arge: -18(SP)

However on page 6 the assemble routine shows that the first argument offset is at 6 and the second argument offset is at 9. i.e.

ld de, (ix+6) ; get first variable and load onto register de
ld hl, (ix+9) ; get second variable and load onto register hl
add hl, de ; add the two values

Shouldn't the first argument offset be at 3 and the second one at 6?
Kindly explain this ambiguity ?.

Regards,

Nick.
Nick Abraham (User)
Fresh Boarder
Posts: 5
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#1013
Re:Calling Assembly code from C 10 Months, 4 Weeks ago Karma: 0
Hello Nick, on page 6 IX if first being pushed onto the stack which uses another 3 bytes of stack, then IX is set equal to the stack pointer, that is why the arguments are offset by 6 and 9 bytes from IX
Bill Glaub (User)
used zilog for over 30 years
Fresh Boarder
Posts: 12
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Raleigh, NC Birthday: 06/09
The administrator has disabled public write access.
 
#1014
Re:Calling Assembly code from C 10 Months, 4 Weeks ago Karma: 0
here is a snip out of some working ez80 code that passed 4 pointers to an asm function, the asm functions returns 1 or 0

;
; int Authenticate( unsigned char * ssn, char * authString, int * ctl1, int * ctl2 );

_Authenticate:
push ix
ld ix,0
add ix,sp ; ix + 6 => ssn, +9=>auth, +12=>ctl1, +15=>ctl2

ld hl,(ix+6) ; point to ssn
; do some stuff here, hl is the ssn pointer


ld de,(ix+9) ; auth pointer
; do some stuff here, de is the authString pointer

ld de,(ix+12) ; de=> caller's ctl1
; do some stuff here, de points to ctl1


ld de,(ix+15) ; de=> caller's ctl2
; do some stuff here, de points to ctl2

; restore IX and return a result of zero or one

pop ix

ld hl,1 ; good
ret z ; z = good code
ld hl,0 ; bad
ret ; nz = bad code
Bill Glaub (User)
used zilog for over 30 years
Fresh Boarder
Posts: 12
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Raleigh, NC Birthday: 06/09
The administrator has disabled public write access.
 
Go to topPage: 1