Hi, I started reading a book named "Programming from the ground up" but realized it's for Linux, so I installed Ubuntu in my Mac with Qemu to test my code there. It works perfectly. But now I want to program with the Intel syntax, with NASM, in my Mac. So I found a site that explained how to program with NASM. But I have so many questions. Like, for example, in Linux you put:

mov  $1, %eax
mov  $0, %ebx
int  $0x80

And the program quits. Which are the Mac OS X system calls? How can I end a program?

Thanks in advanced

in Linux you put:

mov  $1, %eax
mov  $0, %ebx
int  $0x80

The two most significant things are strip $ and % and invert operators

mov eax, 1
mov ebx, 0
int 0x80

I don't remember what the call is for Linux, but in windows to do an orderly shutdown of an application

xor eax, eax
call ExitProcess

Linux has some 18 different ways of terminating, by sending events to other applications and so on. I don't have a Linux box up and running right now, so can't give any greater detail than this.

Ok I got it to work but now I have another problem. I assembled this in Linux:

.section .data
# We don't have any global data.
.section .text
.globl _start
_start:
	pushl $5
	call  sqwr
	popl  %ebx
	movl  %eax, %ebx
	movl  $1, %eax
	int   $0x80
.type sqwr, @function
sqwr:
	pushl %ebp
	movl  %esp, %ebp
	movl  8(%ebp), %eax
	imul  %eax, %eax
	jmp   end_sqwr
end_sqwr:
	movl  %ebp, %esp
	popl  %ebp
	ret

And it returns 25, the correct value. But when I assembled this in Mac OS X:

section .text
	global _start
_start:
	push	dword 5
	call	_square
	pop	ebx
	mov	ebx, eax
	mov	eax, 1
	call	_syscall
_square:
	push	ebp
	mov	ebp, esp
	mov	eax, [ebp + 8]
	imul	eax, eax
	mov	esp, ebp
	pop	ebp
	ret
_syscall:
	int	0x80
	ret

It returned 1. What happened? The only thing that I changed was the syntax.

Ok, I got it. I wasn't returning anything lol, so I added:

push ebx

before:

mov eax, 0x1

This article has been dead for over six months. Start a new discussion instead.