37 lines
779 B
NASM
37 lines
779 B
NASM
|
; echo.asm
|
||
|
; Demo: C und Assembler verlinken
|
||
|
; HS Emden/Leer | C.Koch
|
||
|
; 31.05.2013 initial version
|
||
|
; 11.12.2014 local variables added
|
||
|
|
||
|
; **** Code-Segment ****
|
||
|
section .text
|
||
|
|
||
|
global _echo
|
||
|
|
||
|
_echo:
|
||
|
push ebp ; neuer Stackframe: BasePointer retten
|
||
|
mov ebp,esp ; Stackpointer zum neuen BasePointer machen
|
||
|
|
||
|
sub esp, 4 ; ?
|
||
|
mov [ebp-4], word 1
|
||
|
|
||
|
mov eax,0 ; Rueckgabewert zur C-Funktion: EAX-Register
|
||
|
add ax, word [foo] ; ?
|
||
|
add ax, word [ebp+8] ; Parameter holen
|
||
|
add ax, word [ebp-4] ; ?
|
||
|
|
||
|
mov esp, ebp ; ?
|
||
|
pop ebp ; BP wiederherstellen
|
||
|
ret ; um die Uebergabeparameter kuemmert sich
|
||
|
; das rufende Programm (add esp, 16)
|
||
|
|
||
|
; **** Daten-Segment ****
|
||
|
section .data
|
||
|
|
||
|
; GLOBALE Variable anlegen und initialisieren.
|
||
|
; C-Beispiel: short foo = 0;
|
||
|
foo dw 2
|
||
|
|
||
|
|