mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-06-01 18:41:13 -07:00
attempts at warmup exercises.
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
.psx
|
|
||||||
.create "exercise1.bin", 0x80010000
|
|
||||||
|
|
||||||
; Entry Point of Code
|
|
||||||
.org 0x80010000
|
|
||||||
|
|
||||||
; Constant declaration
|
|
||||||
BASE_ADDR equ 0x0000
|
|
||||||
|
|
||||||
|
|
||||||
; Symbol Alias Table
|
|
||||||
|
|
||||||
; Instructions
|
|
||||||
load_imm equ li
|
|
||||||
|
|
||||||
; Registers
|
|
||||||
rtemp_0 equ $t0
|
|
||||||
rtemp_1 equ $t1
|
|
||||||
rtemp_2 equ $t2
|
|
||||||
|
|
||||||
.macro test,dst_reg,value
|
|
||||||
li dst_reg,value
|
|
||||||
.endmacro
|
|
||||||
|
|
||||||
.macro test2,reg
|
|
||||||
li reg,0xA000
|
|
||||||
.endmacro
|
|
||||||
|
|
||||||
.macro myli,dest,value
|
|
||||||
.if value & ~0xFFFF
|
|
||||||
ori dest,r0,value
|
|
||||||
.elseif (value & 0xFFFF8000) == 0xFFFF8000
|
|
||||||
addiu dest,r0,value & 0xFFFF
|
|
||||||
.elseif (value & 0xFFFF) == 0
|
|
||||||
lui dest,value >> 16
|
|
||||||
.else
|
|
||||||
lui dest,value >> 16 + (value & 0x8000 != 0)
|
|
||||||
addiu dest,dest,value & 0xFFFF
|
|
||||||
.endif
|
|
||||||
.endmacro
|
|
||||||
|
|
||||||
.macro store_word, src_reg, dst_address
|
|
||||||
sw src_reg, dst_address
|
|
||||||
.endmacro
|
|
||||||
|
|
||||||
Main:
|
|
||||||
myli $t0, 0xA000
|
|
||||||
li rtemp_1, 0xA100 ; $t1 = 0xA100
|
|
||||||
li rtemp_2, 0x11111111 ; $t2 = 0x11111111
|
|
||||||
|
|
||||||
Loop:
|
|
||||||
sw $t2, BASE_ADDR($t0) ; Store byte at 0x0000 + t0
|
|
||||||
addi $t0, $t0, 4 ; ++ t0
|
|
||||||
blt $t0, $t1, Loop ; while (t0 < t1) keep looping
|
|
||||||
|
|
||||||
.close
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
.psx
|
||||||
|
.create "exercise_1.bin", 0x80010000
|
||||||
|
|
||||||
|
; Entry Point of Code
|
||||||
|
.org 0x80010000
|
||||||
|
|
||||||
|
; Constant declaration
|
||||||
|
BASE_ADDR equ 0x0000
|
||||||
|
|
||||||
|
; Symbol Alias Table
|
||||||
|
|
||||||
|
; Instructions
|
||||||
|
load_imm equ li ; dst_reg, immeidate value
|
||||||
|
store_word equ sw ; src_reg, dst_address
|
||||||
|
|
||||||
|
; Registers
|
||||||
|
rtemp_0 equ $t0
|
||||||
|
rtemp_1 equ $t1
|
||||||
|
rtemp_2 equ $t2
|
||||||
|
|
||||||
|
main:
|
||||||
|
; TODO:
|
||||||
|
; 1. Load $t0 with the immediate decimal value of 1
|
||||||
|
; 2. Load $t1 with the immediate decimal value of 256
|
||||||
|
; 3. Load $t2 with the immediate decimal value of 17
|
||||||
|
|
||||||
|
; Attempt:
|
||||||
|
load_imm rtemp_0, 1
|
||||||
|
load_imm rtemp_1, 256
|
||||||
|
load_imm rtemp_2, 17
|
||||||
|
end:
|
||||||
|
.close
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
.psx
|
||||||
|
.create "exercise_2.bin", 0x80010000
|
||||||
|
|
||||||
|
; Entry Point of Code
|
||||||
|
.org 0x80010000
|
||||||
|
|
||||||
|
; Constant declaration
|
||||||
|
BASE_ADDR equ 0x0000
|
||||||
|
|
||||||
|
; Symbol Alias Table
|
||||||
|
|
||||||
|
; Instructions
|
||||||
|
; Load
|
||||||
|
load_imm equ li ; dst_reg, immeidate value
|
||||||
|
; Store
|
||||||
|
store_word equ sw ; src_reg, dst_address
|
||||||
|
; Addition
|
||||||
|
add_s equ add ; dst_reg, reg_a, reg_b (signed)
|
||||||
|
add_u equ add ; dst_reg, reg_a, reg_b (unsigned)
|
||||||
|
add_si equ addi ; dst_reg, src_reg, immediate value (signed)
|
||||||
|
add_ui equ addiu ; dst_reg, src_reg, immediate value (unsigned)
|
||||||
|
; Branch
|
||||||
|
branch_equal equ beq ; reg, value(reg, immediate), dst_label
|
||||||
|
|
||||||
|
; Registers
|
||||||
|
; Temporaries, may be changed by subroutines
|
||||||
|
rtemp_0 equ $t0
|
||||||
|
rtemp_1 equ $t1
|
||||||
|
rtemp_2 equ $t2
|
||||||
|
|
||||||
|
main:
|
||||||
|
; TODO:
|
||||||
|
; 1. Start $t0 with the value 1 and $t1 with the value 0
|
||||||
|
; 2. Loop, incrementing $t0 until it reaches the value 10
|
||||||
|
; 3. Keep adding and accumulating all values of $t0 inside $t1
|
||||||
|
|
||||||
|
; Attempt:
|
||||||
|
load_imm rtemp_0, 1
|
||||||
|
load_imm rtemp_1, 0
|
||||||
|
loop:
|
||||||
|
add_s rtemp_1, rtemp_1, rtemp_0
|
||||||
|
add_si rtemp_0, rtemp_0, 1
|
||||||
|
branch_equal rtemp_0, 10, end
|
||||||
|
nop
|
||||||
|
j loop
|
||||||
|
end:
|
||||||
|
.close
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
.psx
|
||||||
|
.create "exercise_3.bin", 0x80010000
|
||||||
|
|
||||||
|
; Entry Point of Code
|
||||||
|
.org 0x80010000
|
||||||
|
|
||||||
|
; Constant declaration
|
||||||
|
BASE_ADDR equ 0x0000
|
||||||
|
|
||||||
|
; Symbol Alias Table
|
||||||
|
|
||||||
|
; Instructions
|
||||||
|
; Load
|
||||||
|
load_imm equ li ; dst_reg, immeidate value
|
||||||
|
; Store
|
||||||
|
store_word equ sw ; src_reg, dst_address
|
||||||
|
; Addition
|
||||||
|
add_s equ add ; dst_reg, reg_a, reg_b (signed)
|
||||||
|
add_u equ add ; dst_reg, reg_a, reg_b (unsigned)
|
||||||
|
add_si equ addi ; dst_reg, src_reg, immediate value (signed)
|
||||||
|
add_ui equ addiu ; dst_reg, src_reg, immediate value (unsigned)
|
||||||
|
; Subtraction
|
||||||
|
sub_s equ sub ;
|
||||||
|
sub_u equ subu ;
|
||||||
|
; Branch
|
||||||
|
branch_equal equ beq ; reg, value(reg, immediate), dst_label
|
||||||
|
branch_gt_equal equ bge ; reg, value(reg, immediate), dst_label
|
||||||
|
branch_lt equ blt ; reg, value(reg, immediate), dst_label
|
||||||
|
|
||||||
|
; Registers
|
||||||
|
; Temporaries, may be changed by subroutines
|
||||||
|
rtemp_0 equ $t0
|
||||||
|
rtemp_1 equ $t1
|
||||||
|
rtemp_2 equ $t2
|
||||||
|
|
||||||
|
; /* C code: */
|
||||||
|
; main() {
|
||||||
|
; int num; // Assume num is loaded in $t0
|
||||||
|
; int den; // Assume den is loaded in $t1
|
||||||
|
; int res; // Assume res is loaded in $t2
|
||||||
|
; num = 27; // Or any other number that we want
|
||||||
|
; den = 3; // Or any other number that we want
|
||||||
|
; res = 0;
|
||||||
|
; while (num >= den) {
|
||||||
|
; num -= den;
|
||||||
|
; res++;
|
||||||
|
; }
|
||||||
|
; }
|
||||||
|
|
||||||
|
main:
|
||||||
|
; TODO:
|
||||||
|
; 1. Initialize $t0 to 27 (or any other value)
|
||||||
|
; 2. Initialize $t1 to 3 (or any other value)
|
||||||
|
; 3. Initialize $t2 (res) with 0
|
||||||
|
; 4. While ($t0 >= $t1) {
|
||||||
|
; 5. Subtract $t0-$t1 and store it back into $t0
|
||||||
|
; 6. Increment $t2
|
||||||
|
; 7. }
|
||||||
|
|
||||||
|
; Attempt:
|
||||||
|
load_imm rtemp_0, 27
|
||||||
|
load_imm rtemp_1, 3
|
||||||
|
load_imm rtemp_2, 0
|
||||||
|
loop: :: branch_lt rtemp_0, rtemp_1, loop_break :: nop ; loop if < rtemp_0, rtemp_1 {
|
||||||
|
sub_s rtemp_0, rtemp_0, rtemp_1 ; -= rtemp_0, rtemp_1
|
||||||
|
add_si rtemp_2, rtemp_2, 1 ; ++ rtemp_2
|
||||||
|
j loop :: loop_break: ; }
|
||||||
|
.close
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Docs
|
||||||
|
|
||||||
|
[psx-spx: Playstation Specifications](https://psx-spx.consoledev.net)
|
||||||
+3
-1
@@ -33,4 +33,6 @@ function build-program { param(
|
|||||||
pop-location
|
pop-location
|
||||||
}
|
}
|
||||||
# build-program 'fillmem' 'fillmem'
|
# build-program 'fillmem' 'fillmem'
|
||||||
build-program 'warmup' 'exercise1'
|
# build-program 'warmup' 'exercise_1'
|
||||||
|
# build-program 'warmup' 'exercise_2'
|
||||||
|
build-program 'warmup' 'exercise_3'
|
||||||
Reference in New Issue
Block a user