某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 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗