Skip to content

risc-v assembly code outputting squares of integers by by Bruce Hoult

Notifications You must be signed in to change notification settings

adingbatponder/risc-v_assembly_1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

risc-v_assembly_1

Risc-v assembly code outputting squares of integers by Bruce Hoult

The code:

	.global main, printf

main:	addi sp,sp,-32
	sd s1,16(sp)
	sd s0,8(sp)
	sd ra,0(sp)

	la a0,hello
	jal printf

	li s0,1
	li s1,10
1:	la a0,sqmsg
	mv a1,s0
	mul a2,s0,s0
	jal printf
	addi s0,s0,1
	blt s0,s1,1b

	ld ra,0(sp)
	ld s0,8(sp)
	ld s1,16(sp)
	addi sp,sp,32
	ret

hello:	.asciz "Hello asm!\n"
sqmsg:	.asciz "%d squared = %d\n"

hardware and operating system: used visionfive V1 risc-v single board computer (SBC) (like a raspberry pi size)

System:
  Host: fedora-starfive Kernel: 5.15.10+ riscv64 bits: 64 Console: tty pts/0 
  Distro: Fedora release 33 (Rawhide) 

complier: gcc (GCC) 10.3.1 20210422 (Red Hat 10.3.1-1). The GNU c compiler gcc was already installed in the operating system, which was provided by the manufacturer/supplier of SBC the on a flash drive.

Execution commands: , with hello.s in the directory shown:

[adingbatponder@fedora-starfive code]$ gcc hello.s -o hello
[adingbatponder@fedora-starfive code]$ ./hello

Output: to terminal screen

Hello asm!
1 squared = 1
2 squared = 4
3 squared = 9
4 squared = 16
5 squared = 25
6 squared = 36
7 squared = 49
8 squared = 64
9 squared = 81

Explanatory remarks: 1b in the line blt s0, s1, 1b is a local symbol name referring back to the loop labled 1, as explained in the GNU manual here

About

risc-v assembly code outputting squares of integers by by Bruce Hoult

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published