Declare assembler variable for C source file

OP #7600870
Rate this post
• ▲ useful
▼ not useful

Hello,

I would like to use an existing function with assembly code in a C program. By this I mean that I want to insert and use an existing function from an old program with assembly code into my new C program (C source file, assembly code inside a C source file). How should register R1 (or a general variable) be declared in my assembler code in order to be able to use R1 in the C source file? My function (Assembler-Code)

1
NAME  KEY_BOARD
2

3
TASTEN_PORT     EQU P1             ; benuetzter PORT
4
P_ANZ           EQU  03H           ; Anzahl Portleitungen
5
;TASTATUR_MODUS  BIT  [0]          ; Steuerbit fuer Modus (20.0)
6
EINGAENGE       EQU  00010111B     ; Maske fuer Tastaturport:
7
                   ; Tastaturpins = 1
8
                  ; unbenuetzte Portpins:
9
                  ; Eingaenge : 1
10
                  ; Ausgaenge : 0
11
TASTEN_NUMMER   EQU  01H          ; Register 1
12
SPALTEN_ZAEHLER EQU  02H          ;          2
13
ZEILEN_ZAEHLER  EQU  03H          ;          3
14
AUSGABE_MASKE   EQU  04H          ;          4
15
EINLESE_MASKE   EQU  05H          ;          5
16

17
ZAHLEN          EQU    00H
18
FERTIG          EQU    03H
19
LOESCHEN        EQU    05H
20
  
21
REGISTER_1    EQU  R1
22
;REGISTER_2    EQU  R2
23
  
24
CARRY_BIT    BIT PSW.7  ;CY
25
  
26
;public Register
27
  
28
;?DT?DATA_SEG  segment data
29
;  RSEG  ?DT?DATA_SEG
30
    
31
;Register  ds   1
32

33
?PR?key_board?KEY_BOARD    SEGMENT CODE
34
  EXTRN  CODE (c_func)
35
  EXTRN   CODE (key_input)
36
  EXTRN   DATA (key_in)
37
  PUBLIC  CARRY_BIT
38
  PUBLIC  key_board
39

40
  RSEG  ?PR?key_board?KEY_BOARD
41
key_board:
42
;****************************************************************
43
   MOV   A,TASTEN_PORT      ; Pruefen, ob Taste noch
44
   ANL   A,R5               ; aktiv ist
45
   JZ    TADA               ; Sprung, falls Taste aktiv
46
   SJMP  WARTE              ; Modus 0+1 : Taste wieder inaktiv
47

48
TADA:
49
   SJMP  KEINE_TASTE1       ; Modus = 1 : alte Taste noch aktiv
50

51
WARTE:
52
   LCALL ENTPRELL           ; Entprellzeit abwarten
53
   MOV   A,TASTEN_PORT      ; Pruefen ob Taste noch aktiv ist
54
   ANL   A,R5
55
   JZ    WARTE              ; Sprung, falls Taste noch prellt
56

57
STARTE_ZYKLUS:
58
    MOV   R4,#0FEH           ; Startwert fuer Ausgabemaske
59
    MOV   R1,#00H           ; Startwert fuer Tastennummer
60
    MOV   R2,#P_ANZ         ; Startwert fuer Spaltenzaehler
61

62
....
63
   RET
64

65
   END

My C-Programm

1
extern void key_board(void);
2
extern unsigned char R1;     // ?
3

4
main {
5
....
6
 if (R1 == 0x03) { ….. } 
7
....
8
}

I use the Compiler "Keil-C"

Kind Regards Juergen B.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.