This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Declare assembler variable for C source file

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.

Parents
  • how to declare the register R1 in my assembly code to R1 in the C source file to be able to use:

    In a nutshell: you don't.  In a mixed C-with-some-assembly program, you must generally assume that none of core registers of the CPU are free to use by your assembler code.  The compiler needs them for its own work.

    As to the job this particular assembly function is meant to do for you, let's just say that the reasoning by which you decided at this is something you need, or even should do in assembler, is almost certainly flawed.

Reply
  • how to declare the register R1 in my assembly code to R1 in the C source file to be able to use:

    In a nutshell: you don't.  In a mixed C-with-some-assembly program, you must generally assume that none of core registers of the CPU are free to use by your assembler code.  The compiler needs them for its own work.

    As to the job this particular assembly function is meant to do for you, let's just say that the reasoning by which you decided at this is something you need, or even should do in assembler, is almost certainly flawed.

Children
No data