This is my first time assembly. I'm taking it as a college class an I'm totally lost and the teacher is of little help, its basically a self instructed class.
I'm losing my mind. We are using DrPaulCarter.com and I cant get the first code to work. its just a simple enter int and find the sum. The code is given
in the book, but to get it to run, it includes a file needed. which I can't get to work
here is the sample code given.
;
; 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 \masm32\asm_io.inc
%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 terminator
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 in 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 in the .text segment
;
segment .text
global _asm_main
_asm_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
here is the
asm_io.inc that needs to be included.
extern read_int, print_int, print_string
extern read_char, print_char, print_nl
extern sub_dump_regs, sub_dump_mem, sub_dump_math, sub_dump_stack
%macro dump_regs 1
push dword %1
call sub_dump_regs
%endmacro
;
; usage: dump_mem label, start-address, # paragraphs
%macro dump_mem 3
push dword %1
push dword %2
push dword %3
call sub_dump_mem
%endmacro
%macro dump_math 1
push dword %1
call sub_dump_math
%endmacro
%macro dump_stack 3
push dword %3
push dword %2
push dword %1
call sub_dump_stack
%endmacro
How do I include other files in a masm32 program. I've spent a week trying to figure this out and its driving me crazy
include path\asm_io.inc
Quote from: dedndave on February 06, 2010, 07:36:04 AM
include path\asm_io.inc
Dave,
I wonder which assembler supports
%macro dump_mem 3 syntax...
dstudentx,
Try replacing the include asm_io.inc with the actual content of asm_io.inc. Which assembler are you using?
<its NASM>
Not nasm is it?
http://www.asmcommunity.net/board/index.php?board=77.0
dstudentx,
You will not succeed building Nasm code with MASM32, they are different assemblers with different notation. Have you downloaded the recent version of Nasm ? You will need this AND some information on the command line options to build it with Nasm.
that you everyone for the help.
You're right its for nasm. I downloaded the latest, nasm but cannot get it to work.
Quote from: donkey on February 06, 2010, 08:03:54 AM
<its NASM>
No, "it's a GAS GAS GAS"
How did you edit your post without "last edited by"?
The thing that probably tipped me off were the 5 references to a nasm command line :P
Quote from: sinsi on February 06, 2010, 09:00:34 AM
Quote from: donkey on February 06, 2010, 08:03:54 AM
<its NASM>
No, "it's a GAS GAS GAS"
How did you edit your post without "last edited by"?
The thing that probably tipped me off were the 5 references to a nasm command line :P
I put it in brackets to show it had been edited. I had originally thought it was GAS but immediately after I finished typing I realized it was NASM and edited my post, you had already posted so I just put brackets around it. If you edit within a few seconds there is no "last edited by". The macros tipped me off...
QuoteThe macros tipped me off...
As if I didn't hate macros already :bdg