2

I've been reading Assembly Language Step-By-Step (3rd edition; by Jeff Duntemann). I have a Linux box, a Lion box, and a (PPC) Tiger machine I can use. I've been writing small assembly programs with NASM on the Lion and Linux machines, and would like to do so on the Tiger one.

Mind you, I never expected this to be easy.

I'm not quite sure how I should change the code to work on PPC. I've so far ran into three expression syntax errors (lines 2, 3, and 14) that I can't figure out.

(I don't have a firm grasp of the PPC instruction set in the least.)

The code I'm trying to assemble is such: (ignore the line numbers)

1    SECTION .data
2        str: db "Hello, World!",0x10
3        len: equ $-str
4
5    SECTION .bss
6
7    SECTION .text
8        global start
9
10   start:
11       nop
12       mov eax,4
13       mov ebx,1
14       mov ecx,str
15       mov edx,len
16       int 0x80
17
18       mov eax,1
19       mov ebx,0
20       int 0x80

(I do realize that PPC is dying and there's not much point in figuring out its assembly, but learning is never a bad thing.)

Paul R
  • 208,748
  • 37
  • 389
  • 560
Aidan Medcalf
  • 135
  • 1
  • 10
  • 1
    NASM is only for x86/x86_64, it won't work with PPC so you have to use another assembler (for example the GNU assembler GAS). Also mostly everything else is also different for PPC - the instruction set and syscall method in particular - you're better off starting from scratch rather than converting existing code line by line. – user786653 Feb 15 '12 at 16:11
  • (Though NASM does run.) Thank you. – Aidan Medcalf Feb 15 '12 at 16:14
  • 1
    Yes, it would have been more proper to say that it only *targets* x86/x86_64. BTW to get a feel for how PPC code looks you can use `gcc -S hello.c` to have GCC output the assembly code of a C program. – user786653 Feb 15 '12 at 16:22

2 Answers2

4

nasm is an assembler for x86 / x86-64. You need to look at using the native (Mach-O ppc) as or gcc extended asm. It's not just a matter of changing opcodes - some directives will be invalid for ppc too. So you will need a firm grasp on PPC assembly.

It's also premature to say that power is dying. IBM POWER7 is still the "fastest" general purpose processor available. Also consider the Cell architecture and embedded markets.

Brett Hale
  • 21,653
  • 2
  • 61
  • 90
2

You wrote assembly for x86 (Intel i386). That is a different architecture than PowerPC (Motorola). See the PowerPC instruction set here.

Additionally you need to use assembler which understands the PowerPC instruction set, gnu as for instance.

Edit: Without a basic understanding of the instruction set (which is often fundamentally different for each architecture) you will find it impossible to write assembly.

Gunther Piez
  • 29,760
  • 6
  • 71
  • 103
  • 1
    I was mostly wondering if NASM used the same assembly language across platforms (doesn't make terribly much sense, now that I think about it). – Aidan Medcalf Feb 15 '12 at 16:15