We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
how to declare the register R1 in my assembly code to R1 in the C source file to be able to use:
C-Program
extern void key_board(void); extern unsigned char R1; // ? main { .... if (R1 == 0x03) { ….. } .... }
Assembler-Code
NAME KEY_BOARD TASTEN_PORT EQU P1 ; benuetzter PORT P_ANZ EQU 03H ; Anzahl Portleitungen ;TASTATUR_MODUS BIT [0] ; Steuerbit fuer Modus (20.0) EINGAENGE EQU 00010111B ; Maske fuer Tastaturport: ; Tastaturpins = 1 ; unbenuetzte Portpins: ; Eingaenge : 1 ; Ausgaenge : 0 TASTEN_NUMMER EQU 01H ; Register 1 SPALTEN_ZAEHLER EQU 02H ; 2 ZEILEN_ZAEHLER EQU 03H ; 3 AUSGABE_MASKE EQU 04H ; 4 EINLESE_MASKE EQU 05H ; 5 ZAHLEN EQU 00H FERTIG EQU 03H LOESCHEN EQU 05H ?PR?key_board?KEY_BOARD SEGMENT CODE EXTRN CODE (c_func) EXTRN CODE (key_input) PUBLIC key_board RSEG ?PR?key_board?KEY_BOARD key_board: ;**************************************************************** TASTATUR: MOV A,TASTEN_PORT ; Pruefen, ob Taste noch ANL A,R5 ; aktiv ist JZ TADA ; Sprung, falls Taste aktiv SJMP WARTE ; Modus 0+1 : Taste wieder inaktiv TADA: SJMP KEINE_TASTE1 ; Modus = 1 : alte Taste noch aktiv WARTE: LCALL ENTPRELL ; Entprellzeit abwarten MOV A,TASTEN_PORT ; Pruefen ob Taste noch aktiv ist ANL A,R5 JZ WARTE ; Sprung, falls Taste noch prellt STARTE_ZYKLUS: MOV R4,#0FEH ; Startwert fuer Ausgabemaske MOV R1,#00H ; Startwert fuer Tastennummer MOV R2,#P_ANZ ; Startwert fuer Spaltenzaehler ...... RET END
Kind Regards
Juergen B.
The Arm Compiler (and likely all Arm-based compilers) obey the Arm Procedure Call Standard.
https://github.com/ARM-software/abi-aa/releases
When a function is called, registers r0-r3 are used to pass parameters, and the return value is passed back in r0.
When writing asm code to work with C code, you MUST also obey this same standard.
You may wish to also see this Learning Path:
https://learn.arm.com/learning-paths/microcontrollers/efficient_embedded/
Apologies - I believe from other threads you are using 8051 class devices.
thanks for your advice.
I understood the thing with the assembler function in my C source file.
I will of course convert the assembler function to “C”.
But this is not just a simple function to query keys.
My function:
6 buttons should be queried via three port pins (with three diodes for decoupling).
Juergen