



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Jump
Stack pointer manipulation
arg_
arg_N
arg_
arg_N
arg_
arg_N
arg_
arg_N
Saved registers
var_
var_M
arg_
arg_1L
arg_1H
or
PSHz
or BSR
PSHz
or PSHX TSX
Local variables
Return address
Function arguments
reg_
reg_L
reg_
reg_L
Using the stack - Entering a function
arg_
arg_N
arg_
arg_N
arg_
arg_N
Saved registers
var_
var_M
ret
retL
retH
or
PULz
or PULX
Local variables
Return address
Function arguments
reg_
reg_L
reg_
reg_L
Using the stack - Exiting a function
โreturn-and-deallocateโ convention, __pascal
; assembly language version of the main function
import multadd import printf
section .bss product ds.l 1 sum ds.l 1
section .strings format dc.b โproduct = %ldโ,$0a,โsum = %ldโ,$
section .data dc.l 0.
section .text main: ; pushing arguments arg4 to arg2 to the stack ; arg4: pm = &product ldx #product pshx ; arg3: c = 32L = 0x ldx #$ pshx ldx #$ pshx ; arg2: b = 17 = 0x ldaa #$ psha
; storing argument arg1 in the register D ; arg1: a = 258 = 0x ldd #$
jsr multadd
; storing result in the sum variable sty sum std sum+
; push arg3, sum, to the stack ldx sum+ pshx ldx sum pshx ; push arg2, product, to the stack ldx product+ pshx ldx product pshx ; push arg1, #format, to the stack ldx #format pshx ; call function jsr printf
; deallocate argument space pulx pulx pulx pulx pulx
rts end
; assembly language version of the multadd function
tmul_offset EQU 0 tadd_offset EQU 4 a_offset EQU 8 b_offset EQU 12 c_offset EQU 13 pm_offset EQU 17
section .text
multadd: ;--------------------------------------------------------- ; Initialization sequence, similar for different functions ;--------------------------------------------------------- ; storing D register pshb psha
; reserving space for two local variables ; long tadd pshx pshx ; long tmul pshx pshx
; IX set to point to the top of the stack tsx
; Exit sequence ;---------------------------------------------------------
; restore value of the stack pointer txs
; return long result in registers IY and D ; IY:D = tadd ldy tadd_offset,X ldd tadd_offset+2,X
; deallocate space for local variables repeat 4 pulx
; remove register D from the stack pulx
; store return address in register IX pulx
repeat 7 ins
jmp 0,X
end
&product
&product
&product
&product
xx xx
xx
xx
xx
xx
xx
xx
tmul
tadd
D=a
b
c
pm