YourSurrogateGod
December 1st, 2004, 03:05 PM
I'm using nasm in order to mess around a little bit. Here is the small program that I would like to make. I got the source code from the below link (it's a book that's a pdf, but stored in a zipped file, the code start on page 29)...
http://www.drpaulcarter.com/pcasm/redir.php?file=pcasm-book-pdf.zip
; first assembly program.
; first_asm.asm
; to create an executable.
; nasm -f elf first.asm
; gcc -o first first.o driver.c asm_io.o
%include "asm_io.inc"
; these labels refer to strings that are used for output.
prompt1 db "Enter a number - > ", 0
prompt2 db "Enter another number - > ", 0
outmsg1 db "You entered ", 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0
; uninitialized data is put into the .bss segment.
segment .bss
; these labels refer to double words used to store the inputs.
input1 resd 1
input2 resd 1
; code is put into the .text segment.
segment .text
global asm_main
asm_main
enter 0, 0 ; setup the routine.
pusha
mov eax, prompt1 ; move the prompt1 into the register.
call print_string ; print out the prompt1 to the screen.
call read_int ; call the read int and read that integer into the eax register.
mov [input1], eax ; store the data in the register in the input1 value. In this instance the brackets are
; used so as to write into the data part of the variable, as opposed the address one.
call print_nl ; give a new line.
mov eax, prompt2 ; move the prompt2 into the register.
call print_string ; print out the prompt2 to the screen.
call read_int ; read another integer to the eax register.
mov [input2], eax ; store the value inside of eax into the label input2.
call print_nl ; give a new line.
mov eax, [input1] ; move the data in input1 to the eax register.
add eax, [input2] ; add the data inside of input2 to the one in register eax.
mov ebx, eax ; move the data in eax to ebx, so as to get it out of the way.
dump_regs 1 ; print out the values in all of the registers.
dump_mem 2, outmsg1, 1 ; print out the contents of the particular memory.
; print out the results message as a series of steps.
mov eax, outmsg1 ; move the first message to the eax register. Note: Here you are passing the pointer
; to the message, not the message itself inside of outmsg1.
call print_string ; print out the contents that are inside of register eax to the screen. In this
; instance it is a string that is stored in label outmsg1.
mov eax, [input1] ; move the data of input1 to the register eax.
call print_int ; print out the contents that are inside of register eax to the screen. In this
; instance it is an integer that is stored in label input1.
mov eax, outmsg2 ; move the second message to the eax register.
call print_string ; print out the contents that are inside of register eax to the screen. In this
; instance it is a string that is stored in label outmsg2.
mov eax, [input2] ; move the data of input2 to the register eax.
call print_int ; print out the contents that are inside of register eax to the screen. In this
; instance it is an integer that is stored in label input2.
mov eax, outmsg3 ; move the third and last message to the eax register.
call print_string ; print out the contents that are inside of register eax to the screen. In this
; instance it is a string that is stored in label outmsg3.
mov eax, ebx ; move the previously stored value inside of ebx to eax.
call print_int ; print out the contents that are inside of register eax to the screen. In this
; instance it is an integer that was stored in register ebx.
call print_nl
popa
mov eax, 0 ; return back to C.
leave
retIn order to assemble it, I inputted this command "nasm -f elf first.asm" and I got the below error...first.asm:8: fatal: unable to open include file `asm_io.inc'
I have NASM version 0.98.35 compiled on Sep 23 2003 and suse 9.0 kernel 2.4.
My question is, what am I doing wrong?
http://www.drpaulcarter.com/pcasm/redir.php?file=pcasm-book-pdf.zip
; first assembly program.
; first_asm.asm
; to create an executable.
; nasm -f elf first.asm
; gcc -o first first.o driver.c asm_io.o
%include "asm_io.inc"
; these labels refer to strings that are used for output.
prompt1 db "Enter a number - > ", 0
prompt2 db "Enter another number - > ", 0
outmsg1 db "You entered ", 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0
; uninitialized data is put into the .bss segment.
segment .bss
; these labels refer to double words used to store the inputs.
input1 resd 1
input2 resd 1
; code is put into the .text segment.
segment .text
global asm_main
asm_main
enter 0, 0 ; setup the routine.
pusha
mov eax, prompt1 ; move the prompt1 into the register.
call print_string ; print out the prompt1 to the screen.
call read_int ; call the read int and read that integer into the eax register.
mov [input1], eax ; store the data in the register in the input1 value. In this instance the brackets are
; used so as to write into the data part of the variable, as opposed the address one.
call print_nl ; give a new line.
mov eax, prompt2 ; move the prompt2 into the register.
call print_string ; print out the prompt2 to the screen.
call read_int ; read another integer to the eax register.
mov [input2], eax ; store the value inside of eax into the label input2.
call print_nl ; give a new line.
mov eax, [input1] ; move the data in input1 to the eax register.
add eax, [input2] ; add the data inside of input2 to the one in register eax.
mov ebx, eax ; move the data in eax to ebx, so as to get it out of the way.
dump_regs 1 ; print out the values in all of the registers.
dump_mem 2, outmsg1, 1 ; print out the contents of the particular memory.
; print out the results message as a series of steps.
mov eax, outmsg1 ; move the first message to the eax register. Note: Here you are passing the pointer
; to the message, not the message itself inside of outmsg1.
call print_string ; print out the contents that are inside of register eax to the screen. In this
; instance it is a string that is stored in label outmsg1.
mov eax, [input1] ; move the data of input1 to the register eax.
call print_int ; print out the contents that are inside of register eax to the screen. In this
; instance it is an integer that is stored in label input1.
mov eax, outmsg2 ; move the second message to the eax register.
call print_string ; print out the contents that are inside of register eax to the screen. In this
; instance it is a string that is stored in label outmsg2.
mov eax, [input2] ; move the data of input2 to the register eax.
call print_int ; print out the contents that are inside of register eax to the screen. In this
; instance it is an integer that is stored in label input2.
mov eax, outmsg3 ; move the third and last message to the eax register.
call print_string ; print out the contents that are inside of register eax to the screen. In this
; instance it is a string that is stored in label outmsg3.
mov eax, ebx ; move the previously stored value inside of ebx to eax.
call print_int ; print out the contents that are inside of register eax to the screen. In this
; instance it is an integer that was stored in register ebx.
call print_nl
popa
mov eax, 0 ; return back to C.
leave
retIn order to assemble it, I inputted this command "nasm -f elf first.asm" and I got the below error...first.asm:8: fatal: unable to open include file `asm_io.inc'
I have NASM version 0.98.35 compiled on Sep 23 2003 and suse 9.0 kernel 2.4.
My question is, what am I doing wrong?