commit ebb00d7482cf828ed8bd122c2afc07b0fe901831
parent 7a5653aded5380a4b75c94b7140d30d3a9eaaae6
Author: Christos Margiolis <christos@margiolis.net>
Date: Thu, 26 Nov 2020 19:47:11 +0200
new assignment: lab3
Diffstat:
2 files changed, 105 insertions(+), 0 deletions(-)
diff --git a/mips-architecture/lab3_ex1.asm b/mips-architecture/lab3_ex1.asm
@@ -0,0 +1,54 @@
+.data
+ str1: .asciiz "Hello\n"
+ str2: .asciiz "TEI\n"
+ name: .space 64
+
+.text
+.globl main
+
+main:
+ # 1. print a character
+ li $v0, 11
+ la $a0, 'C'
+ syscall
+
+ # 2. print characters 'a' and 'd'
+ li $a0, 'a'
+ syscall
+ li $a0, 'd'
+ syscall
+
+ # 3. print 'Hello'
+ li $v0, 4
+ la $a0, str1
+ syscall
+
+ # 4. print 'Hello' and 'TEI'
+ la $a0, str1
+ syscall
+ la $a0, str2
+ syscall
+
+ # 5. print 5
+ li $v0, 1
+ li $a0, 5
+ syscall
+
+ # 6. read a word and print it
+ li $v0, 5
+ syscall
+ move $t0, $v0
+ li $v0, 1
+ la $a0, 0($t0)
+ syscall
+
+ # 7. read name, store in mem and print it
+ li $v0, 8
+ la $a0, name
+ li $a1, 64
+ syscall
+ li $v0, 4
+ syscall
+
+ li $v0, 10
+ syscall
diff --git a/mips-architecture/lab3_ex2.asm b/mips-architecture/lab3_ex2.asm
@@ -0,0 +1,51 @@
+.data
+ str1: .ascii "hello"
+ str2: .space 64
+ x: .word 0
+ a: .word 20
+ b: .word 30
+ c: .word 15
+
+.text
+.globl main
+
+main:
+ # 1. print 1st and 2nd character in string
+ li $v0, 11
+ lb $a0, str1
+ syscall
+ lb $a0, str1 + 1
+ syscall
+
+ # 2. read x and print str[x]
+ li $v0, 5
+ syscall
+ lb $a0, str1 + 0($v0)
+ li $v0, 11
+ syscall
+
+ # 3. read a string and print its 2nd char
+ li $v0, 8
+ la $a0, str2
+ la $a1, 64
+ syscall
+ lb $a0, str2 + 1
+ li $v0, 11
+ syscall
+
+ # 4. int x, a = 20, b = 30, c = 15;
+ # x = (a + b) - (c + 10);
+ lw $t0, x
+ lw $t1, a
+ lw $t2, b
+ lw $t3, c
+ add $t4, $t1, $t2
+ addi $t5, $t3, 10
+ sub $t0, $t4, $t5
+
+ li $v0, 1
+ la $a0, 0($t0)
+ syscall
+
+ li $v0, 10
+ syscall