⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 first.asm

📁 关于linux环境下的nasm代码的生成和使用
💻 ASM
字号:
;; file: first.asm; First assembly program. This program asks for two integers as; input and prints out their sum.;; To create executable:; Using djgpp:; nasm -f coff first.asm; gcc -o first first.o driver.c asm_io.o;; Using Linux and gcc:; nasm -f elf first.asm; gcc -o first first.o driver.c asm_io.o;; Using Borland C/C++; nasm -f obj first.asm; bcc32 first.obj driver.c asm_io.obj;; Using MS C/C++; nasm -f win32 first.asm; cl first.obj driver.c asm_io.obj;; Using Open Watcom; nasm -f obj first.asm; wcl386 first.obj driver.c asm_io.obj%include "asm_io.inc";; initialized data is put in the .data segment;segment .data;; These labels refer to strings used for output;prompt1 db    "Enter a number: ", 0       ; don't forget nul terminatorprompt2 db    "Enter another number: ", 0outmsg1 db    "You entered ", 0outmsg2 db    " and ", 0outmsg3 db    ", the sum of these is ", 0;; uninitialized data is put in the .bss segment;segment .bss;; These labels refer to double words used to store the inputs;input1  resd 1input2  resd 1 ;; code is put in the .text segment;segment .text        global  asm_mainasm_main:        enter   0,0               ; setup routine        pusha        mov     eax, prompt1      ; print out prompt        call    print_string        call    read_int          ; read integer        mov     [input1], eax     ; store into input1        mov     eax, prompt2      ; print out prompt        call    print_string        call    read_int          ; read integer        mov     [input2], eax     ; store into input2        mov     eax, [input1]     ; eax = dword at input1        add     eax, [input2]     ; eax += dword at input2        mov     ebx, eax          ; ebx = eax        dump_regs 1               ; dump out register values        dump_mem 2, outmsg1, 1    ; dump out memory;; next print out result message as series of steps;        mov     eax, outmsg1        call    print_string      ; print out first message        mov     eax, [input1]             call    print_int         ; print out input1        mov     eax, outmsg2        call    print_string      ; print out second message        mov     eax, [input2]        call    print_int         ; print out input2        mov     eax, outmsg3        call    print_string      ; print out third message        mov     eax, ebx        call    print_int         ; print out sum (ebx)        call    print_nl          ; print new-line        popa        mov     eax, 0            ; return back to C        leave                             ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -