kernelthread.com

SPARC Assembly

The Towers of Hanoi in SPARC Assembly language.

Quoted from SPARC International's home page:

SPARC (which stands for Scalable Processor ARChitecture) is an open set of technical specifications that any person or company can license and use to develop microprocessors and other semiconductor devices based on published industry standards.

SPARC was invented in the labs of Sun Microsystems Inc., based upon pioneering research into Reduced Instruction Set Computing (RISC) at the University of California at Berkeley. The first standard product based on the SPARC architecture was produced by Sun and Fujitsu in 1986; Sun followed in 1987 with its first workstation based on a SPARC processor.

In 1989, Sun Microsystems transferred ownership of the SPARC specifications to an independent, non-profit organization, SPARC International, which administers and licenses the technology and provides compliance testing and other services for its members.

! ! The Towers Of Hanoi ! SPARC Assembly Language ! Copyright (C) 2001 Amit Singh. All Rights Reserved. ! http://hanoi.kernelthread.com ! ! Tested on an Ultra-5 ! .align 4 .global main main: save %sp, -112, %sp st %i0, [%fp + 68] st %i1, [%fp + 72] ! atoi(argv[1]) ! mov 4, %o0 ld [%fp + 72], %o2 add %o0, %o2, %o1 ld [%o1], %o0 call atoi nop mov %o0, %o1 mov %o1, %o0 ! Tower labels { from => 1, to => 3, using => 2 } ! mov 1, %o1 mov 3, %o2 mov 2, %o3 call hanoi nop ret restore MOVESTR: .asciz "%d -> %d\n" .align 4 .global hanoi hanoi: save %sp, -112, %sp st %i0, [%fp + 68] st %i1, [%fp + 72] st %i2, [%fp + 76] st %i3, [%fp + 80] ld [%fp + 68], %o0 ! (n <= 1) ! cmp %o0, 1 bne RECURSE nop ! print the move ! sethi %hi(MOVESTR), %o1 or %o1, %lo(MOVESTR), %o0 ld [%fp + 72], %o1 ld [%fp + 76], %o2 call printf nop b done nop RECURSE: ld [%fp + 68], %o0 add %o0, -1, %o1 mov %o1, %o0 ld [%fp + 72], %o1 ld [%fp + 80], %o2 ld [%fp + 76], %o3 call hanoi nop sethi %hi(MOVESTR), %o1 or %o1, %lo(MOVESTR), %o0 ld [%fp + 72], %o1 ld [%fp + 76], %o2 call printf nop ld [%fp + 68], %o0 add %o0, -1, %o1 mov %o1, %o0 ld [%fp + 80], %o1 ld [%fp + 76], %o2 ld [%fp + 72], %o3 call hanoi nop done: ret restore ! FINIS

Download

hanoi.sparc