Skip to content

Instantly share code, notes, and snippets.

@hybriz
Last active June 19, 2017 13:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hybriz/721c3ce318c573f8e2a55509a6958691 to your computer and use it in GitHub Desktop.
arvorezinha

ages ago (2009) as a joke friends from #C@PTNET.ORG channel started doing an ascii little tree in various programming languages i did mine in assembly on 3 different ISAs: SPARC, PA-RISC and Alpha

i miss old commercial unix and all that free local privesc!

original in Portuguese: https://blol.org/1396-arvorezinha-melhor-arquitectura-do-mundo-alpha https://web.archive.org/web/20110812180220/https://blol.org/1396-arvorezinha-melhor-arquitectura-do-mundo-alpha

this is an internationalized version cause like idk apparently not everyone speaks portuguese for some reason

tru64> gcc arvore.S -o arvorezinha
tru64> ./arvorezinha
*
**
***
****
*****
tru64> cat arvore.S
.data
LF:             .ascii          "\n\0"
GAY:            .ascii          "*"
 
.text
        .align  4
        .set    noreorder
        .arch   ev4
        .globl  main
        .ent    main
 
main:
        ldgp    $gp,0($27)			# load that global pointer
        stq     $26,0($sp)			# initialize? the stack pointer (just in case right)
 
        lda $10,5				# RFC_MAX for main loop
        lda $9,0				# counter for loop1
 
loop1:
        cmpeq $9,$10,$7				# if $9 equals $10, branch to end
        bne $7,final
 
        lda $11,0				# counter for loop2
 
loop2:
        cmple $11,$9,$7				# if $11 less or equal to $9, star it!
        bne $7,estrela
 
        lda $16,LF				# new line pl0x
        jsr $26,printf
        ldgp $gp,0($26)
 
        lda $9,1($9)				# a gay way to increment
        br loop1
 
estrela:
        lda     $16,GAY				# print the little star...
        jsr     $26,printf			# one always needs to reset $gp
        ldgp    $gp,0($26)			# after using a function
 
        addq $11,1,$11				# another gay way to increment :p
        br loop2
 
final:
        mov     $31,$0				# return = 0
        ldq     $26,0($sp)			# cleanup stack, though we didn't use it but oh well..
        ret     $31,($26),1			# returnarrrrrrrrr
        .end    main
 
tru64>

original in Portuguese: https://blol.org/1407-arvorezinha-hp-precision-architecture-aka-pa-risc-aka-demonio

this is an internationalized version cause like idk apparently not everyone speaks portuguese for some reason

hpux$ cat arvorezinha.S
	.LEVEL 1.1						; gay stuff for HPUX
	.SPACE $PRIVATE$					; HPPA has a thing called spaces, read the arch book
	.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31			; for further info on this or early schizophrenia
	.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
	.SPACE $TEXT$
	.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
	.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
	.IMPORT $global$,DATA
	.IMPORT $$dyncall,MILLICODE
	.IMPORT write,CODE					; it is nice to do imports
	.IMPORT exit,CODE
	.IMPORT __main,CODE
	.SPACE $TEXT$
	.SUBSPA $LIT$
 
	.align 4
STAR
	.STRING "\x2a\x00"
LF
	.STRING "\x0a\x00"
	.SPACE $TEXT$
	.SUBSPA $CODE$
 
	.align 4
	.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
	.EXPORT main,ENTRY,PRIV_LEV=3,RTNVAL=GR			; the privilege levels is funny
main
	.PROC
	.CALLINFO FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
	.ENTRY
	.CALL
	xor     %r4,%r4,%r4					; aka set %r4 to zero :)
 
arewedoneyet
	comib,=,n 5,%r4,kk10xbai				; if %r4 is 5, BAI NAO!
	nop
	xor     %r3,%r3,%r3					; initialize counter for 2nd loop
 
letsdothis
	comb,<=,n %r3,%r4,estrela				; if %r3 is less or equal to %r4
	xor %r1,%r1,%r26					; yes, this is a nop
 
	ldi 1,%r26						; choose the fd (1 is stdout)
	ldil LR'LF,%r19						; copy string in
	ldo RR'LF(%r19),%r25					; a sissy way
	ldi 1,%r24						; length of stringue
	.CALL ARGW0=GR,ARGW1=GR,ARGW2=GR
	bl write,%r2
	xor %r1,%r2,%r3						; yes, this is a nop
 
	addi    1,%r4,%r4					; increment %r4
	b       arewedoneyet
	shladd %r4,2,%r8,%r15					; yes, this is a nop
 
estrela
	ldi 1,%r26						; see the other write
	ldil LR'STAR,%r19					; same shit going on
	ldo RR'STAR(%r19),%r25
	ldi 1,%r24
	.CALL ARGW0=GR,ARGW1=GR,ARGW2=GR
	bl write,%r2
	add %r13,%r14,%r15					; yes, this is a nop
 
	addi    1,%r3,%r3
	b       letsdothis
	nop							; guess what...
 
kk10xbai
	ldi 0,%r26
	.CALL ARGW0=GR
	bl exit,%r2
	shrpw %r8,%r7,8,%r9					; nop nop nop
	subi,OD  42,%r3,%r12					; nop nop nop nopppppp! :D
	.EXIT
	.PROCEND
hpux$ gcc arvorezinha.S && ./a.out
*
**
***
****
*****
hpux$

original post in portuguese: https://blol.org/1402-arvorezinha-sparc

this is an internationalized version cause like idk apparently not everyone speaks portuguese for some reason

btw, this arch is somewhat inedible

solaris$ cat arvore.S
.section  ".rodata1"
.align    4
.L0:
        .ascii           "*\0"
.L1:
        .ascii          "\n\0"
 
.L2:
        .ascii          "bla\n\0"
 
        .section        ".text"
        .global         main
main:
        save            %sp,-96,%sp
        mov 0,%g2
 
arewedoneyet:
        cmp %g2,5			! compare with RFC_MAX of course, no registers needed for this
        be weredonefag
 
        mov 0,%g3			! initialize counter1
 
estrelitas:
        cmp %g3,%g2			! ah e tal, compara-me a pissa, less or equal?
        ble estrela
 
        set .L1,%o0			! put LF on output register, demand printing!
        call printf
 
        inc %g2				! increase counter2
        ba arewedoneyet
 
estrela:
        set     .L0,%o0			! printing little star
        call    printf
 
        inc %g3
        ba estrelitas
 
weredonefag:
        nop
        restore
 
solaris$ gcc arvore.S -o arvorezinha
solaris$ ./arvorezinha
*
**
***
****
*****
solaris$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment