0

I am learning SPARC Asm and trying to do some simple exercises, mostly learning from the Internet. But my problem is: I cannot assemble the code, and it's hard for me to find any sources on where and how to do that.

My sample code (should calculate the factorial of a given number):

.global silnia
.proc 4

silnia:
 save %sp, -96, %sp

 subcc %i0, 2, %l0
 bneg silnia1
 nop

 call silnia
 sub %i0, 1, %o0
 ba koniec
 smul %o0, %i0, %i0


silnia1:
 ba koniec
 mov 1, %i0

koniec:
 ret
 restore
#include <stdio.h>
extern int silnia(int n);

int main() {
 int a, b;

 for(b = 0; b <= 13; b++) {
  a = silnia(b);
  printf("silnia %i = %i\n", b, a);
 }

 return 0;
}

The command I'm using:
gcc -g -o output silnia.c silnia

Output: a bunch of unrecognized instructions and registers in the .s file, almost 1 error in each line.

I tried it on two different Linux-based OSes: Ubuntu 22.04 and Solaris 11.4 with the same result - it looks like gcc doesn't recognize the ASM syntax. How can I make it run properly?

nooblet
  • 1
  • 1
  • 1
  • 3
    GCC is only going to recognize assembly language syntax for the machine it's running on, by default. You would need a cross-compilation toolchain designed for the SPARC architecture. – jasonharper May 12 '22 at 19:19
  • Or a SPARC machine (real or virtual). – Seva Alekseyev May 12 '22 at 19:44
  • @SevaAlekseyev do you know a source where I can learn how to setup a virtual SPARC machine? – nooblet May 12 '22 at 19:49
  • @SevaAlekseyev Yes, and after searching through dozens of sources, none of which answered any of my questions, I made a thread on StackOverflow. – nooblet May 12 '22 at 19:59

0 Answers0