Assembly access violation

I am following this tutorial: http://www.drpaulcarter.com/pcasm/

So i got to my first program i have copied everything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
; 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

%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 null 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 ; print out register values
dump_mem 2, outmsg1, 1 ; print 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

and the driver.c

1
2
3
4
5
6
int main()
{
    int ret_status ;
    ret_status = asm_main();
    return ret_status ;
}

I compile it as:
nasm -f coff first.asm
gcc -o first first.o driver.c asm_io.o

Everything is ok no warnings or errors. But when i open the .exe file it crashes.
What can I do?
Windows 7
Last edited on
compile it as elf instead of coff

I exactly had the same problem
Last edited on
i tried that too and still crash
Use gdb! Compile your assembly code with debugging symbols and step through your program. It's super difficult to get an asm program right your first couple tries, debugging will help by showing where the issue is!
Last edited on
Topic archived. No new replies allowed.