2016-08-23 08:42 AM
Hello,
I looking for some example code for call one function in a assembly file from/in C code. Can someone help me with it? Sorry, I'm beginner in this branch...
Thank you very much.
#c #programming #assembly2016-08-23 10:06 AM
This is for an F4 in Keil, but is illustrative, it is not complicated.
;*****************************************************************************
; In C code
; Prototype as
; extern void SystemReset(void);
; Call as
; SystemReset()
SystemReset PROC
EXPORT SystemReset
ldr r1, =0xE000ED0C ; NVIC Application Interrupt and Controller
ldr r0, =0x05FA0004 ; Magic
str r0, [r1, #0] ; Reset
b .
bx lr
ENDP ; SystemReset
;*****************************************************************************
; In C code
; Prototype as
; extern void KickWatchdog(void);
; Call as
; KickWatchdog()
KickWatchdog PROC
EXPORT KickWatchdog
ldr r0, =0x40003000 ; IWDG
movw r1, #0xAAAA
str r1, [r0, #0] ; IWDG_KR Reload / Kick
bx lr
ENDP ; KickWatchdog sourcer32@gmail.com
;*****************************************************************************
; In C code
; Prototype as
; extern void InitWatchdog(void);
; Call as
; InitWatchdog()
InitWatchdog PROC
EXPORT InitWatchdog
ldr r0, =0x40003000 ; IWDG
movw r1, #0x5555
str r1, [r0, #0] ; IWDG_KR Enable Access
movw r1, #6 ; /256
str r1, [r0, #4] ; IWD_PR Prescaler Register
movw r1, #0xFFF ; Reload value, reset default, writing for clarity, 768s
str r1, [r0, #8] ; IWD_RLR Reload Register
movw r1, #0xAAAA
str r1, [r0, #0] ; IWDG_KR Reload
movw r1, #0xCCCC
str r1, [r0, #0] ; IWDG_KR Enable
bx lr
ENDP ; InitWatchdog
;*****************************************************************************
Assembler threads
/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Assembly%20Code%20Example&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=8665
;*****************************************************************************
; In C code
; Prototype as
; extern int foo(int, int, int);
; Call as
; foo(x, y, z)
foo PROC
EXPORT foo
; Calling foo(x, y, z); Will enter foo with R0=x, R1=y, R2=z
; returns R0
ldr r0, =12345 ; return(12345)
bx lr
ENDP ; foo sourcer32@gmail.com
;*****************************************************************************
2016-08-24 02:44 AM
Hi ala.marc,
Check this thread for . -Hannibal-2016-08-30 11:56 AM
I thank you and appreciate for your immediate response.
That helped me a lot.Thank you very much for your time.