如题,打算在.asm和.c互相调用的同时试试修改内存,代码如下:
;-------------------------------------------------------
foo.asm
extern choose
[section .data]
num1st db 'a'
num2nd db 'm'
[section .text]
global _start
global my_print
_start:
;mov num1st, 'z';这一行去掉分号编译报错“error: invalid combination of opcode and operands”
push dword [num2nd]
push dword [num1st]
call choose
add esp, 8;这一行作用不明。。。。
mov ebx, 0
mov eax, 1
int 0x80
my_print:
mov ecx, [esp+4]
mov edx, [esp+8]
mov ebx, 1
mov eax, 4
int 80h
ret
;-------------------------------------------------------
//======================================================
bar.c
extern void my_print(char* str, int len);
int choose(char first, char second){
if(first>=second){
my_print("the 1st one is bigger\n",23);
}else{
my_print("the 2nd one is bigger\n",23);
}
return 0;
}
//======================================================
p.s., 小弟在看《orange's一个操作系统的实现》和《CRC.X86 Assembly Language and C Fundamentals.2013》,感觉两本书讲的不是同一个东西……