某Zz 2014-05-26 13:17
浏览 1962

x86汇编里如何向一个内存单元写数据

如题,打算在.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》,感觉两本书讲的不是同一个东西……

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?
    • ¥15 电磁场的matlab仿真
    • ¥15 mars2d在vue3中的引入问题
    • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
    • ¥15 算法题:数的划分,用记忆化DFS做WA求调
    • ¥15 chatglm-6b应用到django项目中,模型加载失败
    • ¥15 CreateBitmapFromWicBitmap内存释放问题。
    • ¥30 win c++ socket
    • ¥15 C# datagridview 栏位进度