/*------------------------------ some data declarations -------------------------------*/ .section ".data" hdr: .asciz "This is a Test Assembly Program" msg1: .asciz "Enter a number " /*------------------------------ the program -------------------------------*/ .section ".text" .align 4 .global main main: save %sp,-64,%sp sethi %hi(hdr),%o0 /* load address of greeting */ or %o0,%lo(hdr),%o0 /* ditto - takes 2 steps */ call prtstring /* print greeting */ nop /* be carefule of these */ sethi %hi(msg1),%o0 /* load address of msg1 */ or %o0,%lo(msg1),%o0 /* ditto - takes 2 steps */ call prtstring /* print msg1 */ nop call rdnum /* read a number from user */ nop clr %l0 /* clear working reg */ loop: add %o0,%l0,%l0 /* add %o0 to %l0 */ subcc %o0,1,%o0 /* decrement %o0 and set cc */ bg loop /* repeat if > 0 */ nop mov %l0,%o0 /* print the answer */ call prntnum nop call rdstring /* read a string () */ nop call rdstring /* read a string */ nop call prtstring /* print a string */ nop mov 1,%g1 ta 0 /*------------------- The C functions (compiled separately): int rdnum() { int i; scanf("%d",&i); return(i); } prntnum(int i) { printf("Answer is %d\n",i); } char * rdstring() { static char x[256]; gets(x); return(&x); } void prtstring(char *x) { printf("%s\n",x); } --------------------*/