assembly language

Bookmarking Digg Diigo DZone Earthlink Google
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Assembler (PowerPC)

Author:Berthold Stöger
Score: (3.37 in 140 votes)
# 99 bottles of beer in PowerPC-Assembler on Linux
# Compile with "gcc -nostdlib -s bottle.s"
# Tested with gcc version 3.3.5 on Linux 2.6.12 for PPC
	.section	.rodata
	.align 1
	.byte	"0No more bottles of beer on the wall, no more bottles of beer."
	.byte	'\n'
	.byte	"Go to the store and buy some more, 99 bottles of beer on the wall."
	.byte	'\n'
	.byte	"0Take one down and pass it around, | bottle{ of beer on the wall."
	.byte	'\n','\n'
	.byte	"0| bottle{ of beer on the wall, | bottle{ of beer."
	.byte	'\n'
	.byte	"0no more"

	.section	.text
	.align 2
	.globl _start
	mr	15,1		# r15 = stack base
	subi	1,1,200		# make place for string
	li	16,99		# r16 = counter
	lis	2,.s1@ha
	la	2,.s1@l(2)
	bl	.print
	subi	16,16,1
	bl	.print
	cmpwi	0,16,0
	bne	.l3
	bl	.print

	li	0,1		# SYS_exit
	li	3,0		# returncode = 0
	sc			# syscall

	mr	4,15
	lbzu	3,-1(2)

	cmpwi	0,3,'0'
	beq	.l1_exit
	cmpwi	0,3,'{'
	blt	.l1_char
	bgt	.l1_count
	cmpwi	0,16,1
	beq	.l1
	li	3,'s'
	stbu	3,-1(4)
	b	.l1
	cmpwi	0,16,0
	bgt	.l1_pos
	lis	5,.nomore@ha
	la	5,.nomore@l(5)
	lbzu	3,-1(5)
	cmpwi	0,3,'0'
	beq	.l1
	stbu	3,-1(4)
	b	.l2
	li	6,10
	divw	3,16,6		# Urgh. PPC doesn't supply
	mullw	6,3,6		# the remainder of divisions...
	sub	5,16,6
	addi	5,5,'0'
	stbu	5,-1(4)
	cmpwi	0,3,0
	ble	.l1
	addi	3,3,'0'
	stbu	3,-1(4)
	b	.l1
	stbu	3,-1(4)
	b	.l1
	li	0,4		# SYS_write
	li	3,1		# fd = stdout
	sub	5,15,4		# len
	sc			# syscall


Download Source | Write Comment

Alternative Versions

Much more efficientCrest da Zoltral05/21/083


>>  barrym said on 07/15/10 04:50:04

barrym From an amateur's perspective, I prefer the look and feel of this source
over the "much more efficient" version. Am I being retardeD?

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!




Security Code: