Commit ad1af058 authored by Pavel Pisa's avatar Pavel Pisa

seminaries/qtmips/call-syscall/l10-05-call-6args.S: implement the code from other example copy.

Signed-off-by: Pavel Pisa's avatarPavel Pisa <>
parent b9f79ba1
// select core without pipeline but with delay slot
#pragma qtmips show registers
#pragma qtmips show memory
.equ SPILED_REG_LED_LINE, 0xffffc104 // 32 bit word mapped as output
.equ STACK_INIT, 0x01230000 // The bottom of the stack, the stack grows down
.set noreorder
.globl start
.globl _start
// int main(){
// int res;
// res = complex(1,2,3,4,5,6);
// return res;
// }
// mips-elf-gcc -c -O6 l10-call-6args.c
// mips-elf-objdump --source -M no-aliases l10-call-6args.o
la $sp, STACK_INIT
jal main
beq $0, $0, final
addiu $sp, $sp, -32 // allocate space for save and arguments
sw $ra, 28($sp) // store return address from main
addiu $v0, $zero, 6 // 6-th argument value
sw $v0, 20($sp) // 6-th argument to the stack
addiu $v0, $zero, 5 // 5-th argument value
sw $v0, 16($sp)
addiu $a3, $zero, 4 // 4-th argument value
addiu $a2, $zero, 3 // 3-rd argument value
addiu $a1, $zero, 2 // 2-nd argument value
jal complex // call complex function
addiu $a0, $zero, 1 // store 1-st argument, run in delay slot
lw $ra, 28($sp) // restore return address
nop // on MIPS1 lw result not available directly
jr $ra // return from main, result in v0
addiu $sp, $sp, 32 // free stack frame, run in delay slot
// sequnece to allocate function frame
addiu $sp, $sp, -24 // allocate frame for the function
sw $s8, 16($sp) // store previous fp value
sw $ra, 20($sp) // store return address to allow call subroutine,
// it is not required in leaf node function
or $s8, $sp, $zero // set fp to point to top of the stack
// function body, stack can be freely allocated
// to pas arguments and store local variables
addu $a0, $a0, $a1 // add the arg 0 and 1
lw $v0, 40($s8) // load 5-th argument 24 + 16
addu $a2, $a0, $a2 // add the 2-nd one to the sum
addu $a3, $a2, $a3 // add the 3-rd one to the sum
lw $t0, 44($s8) // load 6-th argument 24 + 20
addu $v0, $a3, $v0 // add 5-h argument
addu $v0, $v0, $t0 // add 6-th one to the summ
// sequence to leave function frame
or $sp, $s8, $zero // restore stack from frame pointer
lw $ra, 20($sp) // restore return address, not necessary in leaf node
lw $s8, 16($sp) // restore previous frame pointer
jr $ra // return from subroutine
addiu $sp, $sp, 24 // free stack frame in delay slot
#pragma qtmips focus memory STACK_INIT-32-24
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment