Skip to content

Instantly share code, notes, and snippets.

@ppdms
Created December 14, 2023 21:14
Show Gist options
  • Select an option

  • Save ppdms/0e3f6c8a4a979e1c721677911144ce75 to your computer and use it in GitHub Desktop.

Select an option

Save ppdms/0e3f6c8a4a979e1c721677911144ce75 to your computer and use it in GitHub Desktop.
.text
.globl _start
_start:
lw $t0, newl
li $t1, 0
main:
li $v0, 12
syscall
beq $v0, $t0, length
sw $v0, ptr($t1)
addi $t1, $t1, 4
j main
length:
bltz $t1, exit
li $v0, 4
la $a0, len
syscall
li $t0, 4
div $t0, $t1, $t0
move $a0, $t0
li $v0, 1
syscall
li $v0, 4
la $a0, newl
syscall
li $t0, -8
addi $t1, $t1, -4
loop:
beq $t0, $t1, exit
li $v0, 11
lw $a0, ptr($t1)
syscall
addi $t1, $t1, -4
j loop
exit:
li $v0, 10
syscall
.data
newl: .asciiz "\n"
.align 7
ptr: .asciiz "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
len: .asciiz "length: "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment