diff options
Diffstat (limited to 'data')
33 files changed, 2780 insertions, 0 deletions
diff --git a/data/.DS_Store b/data/.DS_Store Binary files differnew file mode 100644 index 0000000..6ad1891 --- /dev/null +++ b/data/.DS_Store diff --git a/data/examples/.DS_Store b/data/examples/.DS_Store Binary files differnew file mode 100644 index 0000000..bd8fb93 --- /dev/null +++ b/data/examples/.DS_Store diff --git a/data/examples/Mars4_5.jar b/data/examples/Mars4_5.jar Binary files differnew file mode 100644 index 0000000..0021281 --- /dev/null +++ b/data/examples/Mars4_5.jar diff --git a/data/examples/test1.asm b/data/examples/test1.asm new file mode 100644 index 0000000..b849530 --- /dev/null +++ b/data/examples/test1.asm @@ -0,0 +1,35 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "Hello world" diff --git a/data/examples/test10.asm b/data/examples/test10.asm new file mode 100644 index 0000000..4d0bb1f --- /dev/null +++ b/data/examples/test10.asm @@ -0,0 +1,434 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for fib +fib: +# Entering a new scope. +# Symbols in symbol table: +# println +# i +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 0 +sub $t0 $t0 $t1 +bne $t0 $zero datalabel0 +li $t0 1 +sw $t0 -8($sp) +jr $ra +j datalabel1 +datalabel0: +datalabel1: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 1 +sub $t0 $t0 $t1 +bne $t0 $zero datalabel2 +li $t0 1 +sw $t0 -8($sp) +jr $ra +j datalabel3 +datalabel2: +datalabel3: +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +# Evaluate parameters and save to stack +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 -4 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +sub $t1 $t1 $t2 +sw $t1 -16($sp) +# Update the stack pointer +add $sp $sp -12 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 12 +# Restore $t0-9 registers +lw $t0 -12($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -20($sp) +# Calling function fib +# Save $ra to a register +move $t1 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +sw $t1 -16($sp) +# Evaluate parameters and save to stack +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t3 -4 +# Add the stack pointer address to the offset. +add $t3 $t3 $sp +# Load the value of i. +lw $t2 0($t3) +li $t3 2 +sub $t2 $t2 $t3 +sw $t2 -20($sp) +# Update the stack pointer +add $sp $sp -16 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 16 +# Restore $t0-9 registers +lw $t0 -12($sp) +lw $t1 -16($sp) +# Restore $ra +move $ra $t1 +# Get return value off stack +lw $t1 -24($sp) +add $t0 $t0 $t1 +sw $t0 -8($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel4 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 0 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 1 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 2 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 3 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 4 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 5 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 6 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 7 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 8 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 9 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 10 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel4: .asciiz "This program prints the first 11 numbers of the Fibonacci sequence" diff --git a/data/examples/test11.asm b/data/examples/test11.asm new file mode 100644 index 0000000..f72fb29 --- /dev/null +++ b/data/examples/test11.asm @@ -0,0 +1,92 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# i +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +datalabel1: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 10 +slt $t0 $t0 $t1 +subi $t0 $t0 1 +bne $t0 $zero datalabel2 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 0 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +add $t1 $t1 $t2 +# complete assignment statement with store +sw $t1 0($t0) +# Exiting scope. +addi $sp $sp 4 +j datalabel1 +datalabel2: +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 0 through 9." diff --git a/data/examples/test12.asm b/data/examples/test12.asm new file mode 100644 index 0000000..dbb716b --- /dev/null +++ b/data/examples/test12.asm @@ -0,0 +1,213 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for fib +fib: +# Entering a new scope. +# Symbols in symbol table: +# println +# i +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 0 +sub $t0 $t0 $t1 +bne $t0 $zero datalabel0 +li $t0 1 +sw $t0 -8($sp) +jr $ra +j datalabel1 +datalabel0: +datalabel1: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 1 +sub $t0 $t0 $t1 +bne $t0 $zero datalabel2 +li $t0 1 +sw $t0 -8($sp) +jr $ra +j datalabel3 +datalabel2: +datalabel3: +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +# Evaluate parameters and save to stack +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 -4 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +sub $t1 $t1 $t2 +sw $t1 -16($sp) +# Update the stack pointer +add $sp $sp -12 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 12 +# Restore $t0-9 registers +lw $t0 -12($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -20($sp) +# Calling function fib +# Save $ra to a register +move $t1 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +sw $t1 -16($sp) +# Evaluate parameters and save to stack +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t3 -4 +# Add the stack pointer address to the offset. +add $t3 $t3 $sp +# Load the value of i. +lw $t2 0($t3) +li $t3 2 +sub $t2 $t2 $t3 +sw $t2 -20($sp) +# Update the stack pointer +add $sp $sp -16 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 16 +# Restore $t0-9 registers +lw $t0 -12($sp) +lw $t1 -16($sp) +# Restore $ra +move $ra $t1 +# Get return value off stack +lw $t1 -24($sp) +add $t0 $t0 $t1 +sw $t0 -8($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# i +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +# println +la $a0 datalabel4 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +datalabel5: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 12 +slt $t0 $t0 $t1 +subi $t0 $t0 1 +bne $t0 $zero datalabel6 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +# Calling function fib +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fib +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +add $t1 $t1 $t2 +# complete assignment statement with store +sw $t1 0($t0) +# Exiting scope. +addi $sp $sp 4 +j datalabel5 +datalabel6: +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel4: .asciiz "This program prints the first 12 numbers of the Fibonacci sequence." diff --git a/data/examples/test13.asm b/data/examples/test13.asm new file mode 100644 index 0000000..a459701 --- /dev/null +++ b/data/examples/test13.asm @@ -0,0 +1,296 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# i +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -40 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Evaluate the index expression and store in a register. +li $t1 0 +# Multiply the index by -4. +li $t2 4 +mul $t1 $t1 $t2 +# Add the index offset to the offset. +add $t0 $t0 $t1 +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -40 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Evaluate the index expression and store in a register. +li $t2 0 +# Multiply the index by -4. +li $t3 4 +mul $t2 $t2 $t3 +# Add the index offset to the offset. +add $t1 $t1 $t2 +# Load the value of a. +lw $t0 0($t1) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -40 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Evaluate the index expression and store in a register. +li $t1 2 +# Multiply the index by -4. +li $t2 4 +mul $t1 $t1 $t2 +# Add the index offset to the offset. +add $t0 $t0 $t1 +# Compute rhs for assignment = +li $t1 2 +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -40 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Evaluate the index expression and store in a register. +li $t2 2 +# Multiply the index by -4. +li $t3 4 +mul $t2 $t2 $t3 +# Add the index offset to the offset. +add $t1 $t1 $t2 +# Load the value of a. +lw $t0 0($t1) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 -44 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 2 +# complete assignment statement with store +sw $t1 0($t0) +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -40 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Evaluate the index expression and store in a register. +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 -44 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +# Multiply the index by -4. +li $t2 4 +mul $t1 $t1 $t2 +# Add the index offset to the offset. +add $t0 $t0 $t1 +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 -44 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -40 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Evaluate the index expression and store in a register. +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t3 -44 +# Add the stack pointer address to the offset. +add $t3 $t3 $sp +# Load the value of i. +lw $t2 0($t3) +# Multiply the index by -4. +li $t3 4 +mul $t2 $t2 $t3 +# Add the index offset to the offset. +add $t1 $t1 $t2 +# Load the value of a. +lw $t0 0($t1) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 -44 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +datalabel1: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -44 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 10 +slt $t0 $t0 $t1 +subi $t0 $t0 1 +bne $t0 $zero datalabel2 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -44 +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Evaluate the index expression and store in a register. +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +# Multiply the index by -4. +li $t2 4 +mul $t1 $t1 $t2 +# Add the index offset to the offset. +add $t0 $t0 $t1 +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +# complete assignment statement with store +sw $t1 0($t0) +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +add $t1 $t1 $t2 +# complete assignment statement with store +sw $t1 0($t0) +# Exiting scope. +addi $sp $sp 44 +j datalabel1 +datalabel2: +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -40 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Evaluate the index expression and store in a register. +li $t2 3 +# Multiply the index by -4. +li $t3 4 +mul $t2 $t2 $t3 +# Add the index offset to the offset. +add $t1 $t1 $t2 +# Load the value of a. +lw $t0 0($t1) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -40 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Evaluate the index expression and store in a register. +li $t2 6 +# Multiply the index by -4. +li $t3 4 +mul $t2 $t2 $t3 +# Add the index offset to the offset. +add $t1 $t1 $t2 +# Load the value of a. +lw $t0 0($t1) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -40 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Evaluate the index expression and store in a register. +li $t2 6 +# Multiply the index by -4. +li $t3 4 +mul $t2 $t2 $t3 +# Add the index offset to the offset. +add $t1 $t1 $t2 +# Load the value of a. +lw $t0 0($t1) +li $t1 6 +mult $t0 $t1 +mflo $t0 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This should print 0, 2, 2, 3, 6 and 36" diff --git a/data/examples/test14.asm b/data/examples/test14.asm new file mode 100644 index 0000000..4c16021 --- /dev/null +++ b/data/examples/test14.asm @@ -0,0 +1,289 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for sum +sum: +# Entering a new scope. +# Symbols in symbol table: +# println +# x +# i +# sum +# n +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 -16 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +# Get sum's offset from $sp from the symbol table and initialize sum's address with it. We'll add $sp later. +li $t0 -20 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +datalabel0: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -16 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +# Get n's offset from $sp from the symbol table and initialize n's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of n. +lw $t1 0($t2) +slt $t0 $t0 $t1 +subi $t0 $t0 1 +bne $t0 $zero datalabel1 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -20 +# Get sum's offset from $sp from the symbol table and initialize sum's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +# Get sum's offset from $sp from the symbol table and initialize sum's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of sum. +lw $t1 0($t2) +# Get x's offset from $sp from the symbol table and initialize x's address with it. We'll add $sp later. +li $t3 16 +# Add the stack pointer address to the offset. +add $t3 $t3 $sp +# Get x's base address from the stack. +lw $t3 0($t3) +# Evaluate the index expression and store in a register. +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t5 4 +# Add the stack pointer address to the offset. +add $t5 $t5 $sp +# Load the value of i. +lw $t4 0($t5) +# Multiply the index by -4. +li $t5 4 +mul $t4 $t4 $t5 +# Add the index offset to the offset. +add $t3 $t3 $t4 +# Load the value of x. +lw $t2 0($t3) +add $t1 $t1 $t2 +# complete assignment statement with store +sw $t1 0($t0) +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 4 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +add $t1 $t1 $t2 +# complete assignment statement with store +sw $t1 0($t0) +# Exiting scope. +addi $sp $sp 20 +j datalabel0 +datalabel1: +# Get sum's offset from $sp from the symbol table and initialize sum's address with it. We'll add $sp later. +li $t1 -20 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of sum. +lw $t0 0($t1) +sw $t0 -12($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# i +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel2 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 -44 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 0 +# complete assignment statement with store +sw $t1 0($t0) +datalabel3: +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t1 -44 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of i. +lw $t0 0($t1) +li $t1 10 +slt $t0 $t0 $t1 +subi $t0 $t0 1 +bne $t0 $zero datalabel4 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -44 +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Evaluate the index expression and store in a register. +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +# Multiply the index by -4. +li $t2 4 +mul $t1 $t1 $t2 +# Add the index offset to the offset. +add $t0 $t0 $t1 +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +# complete assignment statement with store +sw $t1 0($t0) +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +# Get i's offset from $sp from the symbol table and initialize i's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of i. +lw $t1 0($t2) +li $t2 1 +add $t1 $t1 $t2 +# complete assignment statement with store +sw $t1 0($t0) +# Exiting scope. +addi $sp $sp 44 +j datalabel3 +datalabel4: +# println +# Calling function sum +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -48($sp) +# Evaluate parameters and save to stack +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t2 -40 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Put the address of the array into the register. +# Use the address of a. +move $t1 $t2 +sw $t1 -52($sp) +li $t1 4 +sw $t1 -56($sp) +# Update the stack pointer +add $sp $sp -48 +# Call the function +jal sum +# Restore the stack pointer +add $sp $sp 48 +# Restore $t0-9 registers +lw $t0 -48($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -60($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function sum +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -48($sp) +# Evaluate parameters and save to stack +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t2 -40 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Put the address of the array into the register. +# Use the address of a. +move $t1 $t2 +sw $t1 -52($sp) +li $t1 8 +sw $t1 -56($sp) +# Update the stack pointer +add $sp $sp -48 +# Call the function +jal sum +# Restore the stack pointer +add $sp $sp 48 +# Restore $t0-9 registers +lw $t0 -48($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -60($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel2: .asciiz "This should print 6 and 28" diff --git a/data/examples/test2.asm b/data/examples/test2.asm new file mode 100644 index 0000000..7f3312a --- /dev/null +++ b/data/examples/test2.asm @@ -0,0 +1,89 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# println +li $t0 7 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +li $t0 3 +li $t1 4 +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +li $t0 14 +li $t1 2 +div $t0 $t1 +mflo $t0 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +li $t0 7 +li $t1 1 +mult $t0 $t1 +mflo $t0 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +li $t0 7 +li $t1 2 +mult $t0 $t1 +mflo $t0 +li $t1 2 +div $t0 $t1 +mflo $t0 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 7 7 7 7 7 (separated by newlines)" diff --git a/data/examples/test3.asm b/data/examples/test3.asm new file mode 100644 index 0000000..69f73f3 --- /dev/null +++ b/data/examples/test3.asm @@ -0,0 +1,73 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# b +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 3 +# complete assignment statement with store +sw $t1 0($t0) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t0 -8 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 4 +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of b. +lw $t1 0($t2) +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints the number 7" diff --git a/data/examples/test4.asm b/data/examples/test4.asm new file mode 100644 index 0000000..db276ba --- /dev/null +++ b/data/examples/test4.asm @@ -0,0 +1,162 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# b +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 3 +# complete assignment statement with store +sw $t1 0($t0) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t0 -8 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 2 +# complete assignment statement with store +sw $t1 0($t0) +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# Update the stack pointer. +addi $sp $sp -8 +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 5 +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t2 0 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of b. +lw $t1 0($t2) +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Entering a new scope. +# Symbols in symbol table: +# println +# b +# Update the stack pointer. +addi $sp $sp -4 +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 9 +# complete assignment statement with store +sw $t1 0($t0) +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 2 +sub $t1 $zero $t1 +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 0 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t2 -4 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of b. +lw $t1 0($t2) +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t0 0 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 4 +# complete assignment statement with store +sw $t1 0($t0) +# Exiting scope. +addi $sp $sp 8 +# println +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of b. +lw $t1 0($t2) +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 7 7 7" diff --git a/data/examples/test5.asm b/data/examples/test5.asm new file mode 100644 index 0000000..76837bc --- /dev/null +++ b/data/examples/test5.asm @@ -0,0 +1,155 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for foo +foo: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +li $t0 7 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for fum +fum: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# b +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 9 +# complete assignment statement with store +sw $t1 0($t0) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t0 -8 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 12 +# complete assignment statement with store +sw $t1 0($t0) +# println +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t1 -8 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of b. +lw $t0 0($t1) +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t2 -4 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of a. +lw $t1 0($t2) +sub $t0 $t0 $t1 +li $t1 4 +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Calling function foo +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +# Evaluate parameters and save to stack +# Update the stack pointer +add $sp $sp -12 +# Call the function +jal foo +# Restore the stack pointer +add $sp $sp 12 +# Restore $t0-9 registers +lw $t0 -12($sp) +# Restore $ra +move $ra $t0 +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Calling function foo +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal foo +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Calling function fum +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal fum +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 7 7 7" diff --git a/data/examples/test6.asm b/data/examples/test6.asm new file mode 100644 index 0000000..1668afa --- /dev/null +++ b/data/examples/test6.asm @@ -0,0 +1,138 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for add +add: +# Entering a new scope. +# Symbols in symbol table: +# println +# x +# i +# y +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +# Get x's offset from $sp from the symbol table and initialize x's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of x. +lw $t0 0($t1) +# Get y's offset from $sp from the symbol table and initialize y's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of y. +lw $t1 0($t2) +add $t0 $t0 $t1 +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# b +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Calling function add +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +# Evaluate parameters and save to stack +li $t1 3 +sw $t1 -16($sp) +li $t1 4 +sw $t1 -20($sp) +# Update the stack pointer +add $sp $sp -12 +# Call the function +jal add +# Restore the stack pointer +add $sp $sp 12 +# Restore $t0-9 registers +lw $t0 -12($sp) +# Restore $ra +move $ra $t0 +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 5 +# complete assignment statement with store +sw $t1 0($t0) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t0 -8 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 2 +# complete assignment statement with store +sw $t1 0($t0) +# Calling function add +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -12($sp) +# Evaluate parameters and save to stack +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t2 -4 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of a. +lw $t1 0($t2) +sw $t1 -16($sp) +# Get b's offset from $sp from the symbol table and initialize b's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of b. +lw $t1 0($t2) +sw $t1 -20($sp) +# Update the stack pointer +add $sp $sp -12 +# Call the function +jal add +# Restore the stack pointer +add $sp $sp 12 +# Restore $t0-9 registers +lw $t0 -12($sp) +# Restore $ra +move $ra $t0 +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 7 7" diff --git a/data/examples/test7.asm b/data/examples/test7.asm new file mode 100644 index 0000000..8414044 --- /dev/null +++ b/data/examples/test7.asm @@ -0,0 +1,141 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for identity +identity: +# Entering a new scope. +# Symbols in symbol table: +# println +# x +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get x's offset from $sp from the symbol table and initialize x's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of x. +lw $t0 0($t1) +sw $t0 -8($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for add +add: +# Entering a new scope. +# Symbols in symbol table: +# println +# x +# y +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get x's offset from $sp from the symbol table and initialize x's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of x. +lw $t0 0($t1) +# Get y's offset from $sp from the symbol table and initialize y's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of y. +lw $t1 0($t2) +add $t0 $t0 $t1 +sw $t0 -12($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function identity +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 7 +sw $t1 -8($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal identity +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -12($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function add +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 3 +sw $t1 -8($sp) +li $t1 4 +sw $t1 -12($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal add +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -16($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 7 7" diff --git a/data/examples/test8.asm b/data/examples/test8.asm new file mode 100644 index 0000000..b9a3263 --- /dev/null +++ b/data/examples/test8.asm @@ -0,0 +1,164 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for add +add: +# Entering a new scope. +# Symbols in symbol table: +# println +# x +# y +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get x's offset from $sp from the symbol table and initialize x's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of x. +lw $t0 0($t1) +# Get y's offset from $sp from the symbol table and initialize y's address with it. We'll add $sp later. +li $t2 -8 +# Add the stack pointer address to the offset. +add $t2 $t2 $sp +# Load the value of y. +lw $t1 0($t2) +add $t0 $t0 $t1 +sw $t0 -12($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for add2 +add2: +# Entering a new scope. +# Symbols in symbol table: +# println +# x +# y +# return +# Update the stack pointer. +addi $sp $sp -0 +# Calling function add +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -16($sp) +# Evaluate parameters and save to stack +# Calling function add +# Save $ra to a register +move $t1 $ra +# Save $t0-9 registers +sw $t0 -16($sp) +sw $t1 -20($sp) +# Evaluate parameters and save to stack +# Get x's offset from $sp from the symbol table and initialize x's address with it. We'll add $sp later. +li $t3 -4 +# Add the stack pointer address to the offset. +add $t3 $t3 $sp +# Load the value of x. +lw $t2 0($t3) +sw $t2 -24($sp) +# Get y's offset from $sp from the symbol table and initialize y's address with it. We'll add $sp later. +li $t3 -8 +# Add the stack pointer address to the offset. +add $t3 $t3 $sp +# Load the value of y. +lw $t2 0($t3) +sw $t2 -28($sp) +# Update the stack pointer +add $sp $sp -20 +# Call the function +jal add +# Restore the stack pointer +add $sp $sp 20 +# Restore $t0-9 registers +lw $t0 -16($sp) +lw $t1 -20($sp) +# Restore $ra +move $ra $t1 +# Get return value off stack +lw $t1 -32($sp) +sw $t1 -20($sp) +li $t1 1 +sw $t1 -24($sp) +# Update the stack pointer +add $sp $sp -16 +# Call the function +jal add +# Restore the stack pointer +add $sp $sp 16 +# Restore $t0-9 registers +lw $t0 -16($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -28($sp) +sw $t0 -12($sp) +jr $ra +# Exiting scope. +addi $sp $sp 0 +jr $ra + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# println +# Calling function add2 +# Save $ra to a register +move $t0 $ra +# Save $t0-9 registers +sw $t0 -4($sp) +# Evaluate parameters and save to stack +li $t1 2 +sw $t1 -8($sp) +li $t1 4 +sw $t1 -12($sp) +# Update the stack pointer +add $sp $sp -4 +# Call the function +jal add2 +# Restore the stack pointer +add $sp $sp 4 +# Restore $t0-9 registers +lw $t0 -4($sp) +# Restore $ra +move $ra $t0 +# Get return value off stack +lw $t0 -16($sp) +move $a0 $t0 +li $v0 1 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints 7" diff --git a/data/examples/test9.asm b/data/examples/test9.asm new file mode 100644 index 0000000..db843e0 --- /dev/null +++ b/data/examples/test9.asm @@ -0,0 +1,239 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# code for main +main: +# Entering a new scope. +# Symbols in symbol table: +# a +# println +# return +# Update the stack pointer. +addi $sp $sp -0 +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t0 -4 +# Add the stack pointer address to the offset. +add $t0 $t0 $sp +# Compute rhs for assignment = +li $t1 3 +# complete assignment statement with store +sw $t1 0($t0) +# println +la $a0 datalabel0 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +li $t1 4 +slt $t0 $t0 $t1 +subi $t0 $t0 1 +bne $t0 $zero datalabel1 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel3 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +j datalabel2 +datalabel1: +datalabel2: +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +li $t1 4 +slt $t0 $t1 $t0 +subi $t0 $t0 1 +bne $t0 $zero datalabel4 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel6 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +j datalabel5 +datalabel4: +datalabel5: +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +li $t1 4 +slt $t0 $t1 $t0 +subi $t0 $t0 1 +bne $t0 $zero datalabel7 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel9 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +j datalabel8 +datalabel7: +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel10 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +datalabel8: +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +li $t1 3 +slt $t0 $t1 $t0 +bne $t0 $zero datalabel11 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel13 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +j datalabel12 +datalabel11: +datalabel12: +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +li $t1 3 +sub $t0 $t0 $t1 +bne $t0 $zero datalabel14 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel16 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +j datalabel15 +datalabel14: +datalabel15: +# Get a's offset from $sp from the symbol table and initialize a's address with it. We'll add $sp later. +li $t1 -4 +# Add the stack pointer address to the offset. +add $t1 $t1 $sp +# Load the value of a. +lw $t0 0($t1) +li $t1 4 +slt $t0 $t0 $t1 +bne $t0 $zero datalabel17 +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel19 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +j datalabel18 +datalabel17: +# Entering a new scope. +# Symbols in symbol table: +# println +# Update the stack pointer. +addi $sp $sp -4 +# println +la $a0 datalabel20 +li $v0 4 +syscall +la $a0 newline +li $v0 4 +syscall +# Exiting scope. +addi $sp $sp 4 +datalabel18: +# Exiting scope. +addi $sp $sp 0 +li $v0 10 +syscall + +# All memory structures are placed after the +# .data assembler directive +.data + +newline: .asciiz "\n" +datalabel0: .asciiz "This program prints [1..5] correct." +datalabel3: .asciiz "1 correct" +datalabel6: .asciiz "2 not correct" +datalabel9: .asciiz "2 not correct" +datalabel10: .asciiz "2 correct" +datalabel13: .asciiz "3 correct" +datalabel16: .asciiz "4 correct" +datalabel19: .asciiz "5 not correct" +datalabel20: .asciiz "5 correct" diff --git a/data/test b/data/test new file mode 100755 index 0000000..89d5b0c --- /dev/null +++ b/data/test @@ -0,0 +1,23 @@ +#! /bin/bash + +java -jar ./Mars4_5.jar test1.asm +java -jar ./Mars4_5.jar test2.asm +java -jar ./Mars4_5.jar test3.asm +java -jar ./Mars4_5.jar test4.asm +java -jar ./Mars4_5.jar test5.asm +java -jar ./Mars4_5.jar test6.asm +java -jar ./Mars4_5.jar test7.asm +java -jar ./Mars4_5.jar test8.asm +java -jar ./Mars4_5.jar test9.asm +java -jar ./Mars4_5.jar test10.asm +java -jar ./Mars4_5.jar test11.asm +java -jar ./Mars4_5.jar test12.asm +java -jar ./Mars4_5.jar test13.asm +java -jar ./Mars4_5.jar test14.asm + +# This loop runs the Java code to create the .asm then runs the .asm. +#for i in {1..14} +#do +# java -cp ../../out/production/p5-compiler:../../antlr-4.9.1-complete.jar main.Main ../test$i.c +# java -jar ./Mars4_5.jar ../test$i.asm +#done diff --git a/data/test1.asm b/data/test1.asm new file mode 100644 index 0000000..6c203dc --- /dev/null +++ b/data/test1.asm @@ -0,0 +1,13 @@ +# All program code is placed after the +# .text assembler directive +.text + +# Declare main as a global function +.globl main + +j main + +# All memory structures are placed after the +# .data assembler directive +.data + diff --git a/data/test1.c b/data/test1.c new file mode 100644 index 0000000..e336f81 --- /dev/null +++ b/data/test1.c @@ -0,0 +1,3 @@ +void main() { + println("Hello world"); +} diff --git a/data/test10.c b/data/test10.c new file mode 100644 index 0000000..a90a21f --- /dev/null +++ b/data/test10.c @@ -0,0 +1,20 @@ +int fib(int i) { + if (i == 0) return 1; + if (i == 1) return 1; + return fib(i-1) + fib(i-2); +} + +void main() { + println("This program prints the first 11 numbers of the Fibonacci sequence"); + println(fib(0)); // 1 + println(fib(1)); // 1 + println(fib(2)); // 2 + println(fib(3)); // 3 + println(fib(4)); // 5 + println(fib(5)); // 8 + println(fib(6)); // 13 + println(fib(7)); // 21 + println(fib(8)); // 34 + println(fib(9)); // 55 + println(fib(10)); // 89 +} diff --git a/data/test11.c b/data/test11.c new file mode 100644 index 0000000..865bcf8 --- /dev/null +++ b/data/test11.c @@ -0,0 +1,9 @@ +void main() { + int i; + i = 0; + println("This program prints 0 through 9."); + while (i < 10) { + println(i); + i = i + 1; + } +} diff --git a/data/test12.c b/data/test12.c new file mode 100644 index 0000000..4bb7f58 --- /dev/null +++ b/data/test12.c @@ -0,0 +1,15 @@ +int fib(int i) { + if (i == 0) return 1; + if (i == 1) return 1; + return fib(i-1) + fib(i-2); +} + +void main() { + int i; + i = 0; + println("This program prints the first 12 numbers of the Fibonacci sequence."); + while (i < 12) { + println(fib(i)); + i = i + 1; + } +} diff --git a/data/test13.c b/data/test13.c new file mode 100644 index 0000000..c1a5c72 --- /dev/null +++ b/data/test13.c @@ -0,0 +1,23 @@ +void main() { + int a[10]; + int i; + + println("This should print 0, 2, 2, 3, 6 and 36"); + a[0] = 0; + println(a[0]); + a[2] = 2; + println(a[2]); + + i = 2; + a[i] = i; + println(a[i]); + + i = 0; + while (i < 10) { + a[i] = i; + i = i + 1; + } + println(a[3]); + println(a[6]); + println(a[6]*6); +} diff --git a/data/test14.c b/data/test14.c new file mode 100644 index 0000000..45565fa --- /dev/null +++ b/data/test14.c @@ -0,0 +1,27 @@ +// Sum the first n elements of the array +int sum(int x[], int n) { + int i; + int sum; + i = 0; + sum = 0; + while (i < n) { + sum = sum + x[i]; + i = i + 1; + } + return sum; +} + +void main() { + int a[10]; + int i; + + println("This should print 6 and 28"); + i = 0; + while (i < 10) { + a[i] = i; + i = i + 1; + } + + println(sum(a, 4)); + println(sum(a, 8)); +} diff --git a/data/test2.c b/data/test2.c new file mode 100644 index 0000000..136ba74 --- /dev/null +++ b/data/test2.c @@ -0,0 +1,8 @@ +void main() { + println("This program prints 7 7 7 7 7 (separated by newlines)"); + println(7); + println(3+4); + println(14/2); + println(7*1); + println((7*2)/2); +} diff --git a/data/test3.c b/data/test3.c new file mode 100644 index 0000000..1083434 --- /dev/null +++ b/data/test3.c @@ -0,0 +1,9 @@ +void main() { + int a; + int b; + + println("This program prints the number 7"); + a = 3; + b = 4; + println(a+b); +} diff --git a/data/test4.c b/data/test4.c new file mode 100644 index 0000000..c4c31c2 --- /dev/null +++ b/data/test4.c @@ -0,0 +1,21 @@ +void main() { + int a; + int b; + + println("This program prints 7 7 7"); + a = 3; + b = 2; + { + int a; + a = 5; + println(a+b); + { + int b; + b = 9; + a = -2; + println(a+b); + } + b = 4; + } + println(a+b); +} diff --git a/data/test5.c b/data/test5.c new file mode 100644 index 0000000..835db83 --- /dev/null +++ b/data/test5.c @@ -0,0 +1,19 @@ +void foo() { + println(7); +} + +void fum() { + int a; + int b; + a = 9; + b = 12; + println(b-a+4); + + foo(); +} + +void main() { + println("This program prints 7 7 7"); + foo(); + fum(); +} diff --git a/data/test6.c b/data/test6.c new file mode 100644 index 0000000..03de49c --- /dev/null +++ b/data/test6.c @@ -0,0 +1,15 @@ +void add(int x, int y) { + int i; + println(x+y); +} + +void main() { + int a; + int b; + println("This program prints 7 7"); + add(3, 4); + + a = 5; + b = 2; + add(a, b); +} diff --git a/data/test7.c b/data/test7.c new file mode 100644 index 0000000..e7f45a5 --- /dev/null +++ b/data/test7.c @@ -0,0 +1,14 @@ +int identity(int x) { + return x; +} + +int add(int x, int y) { + return x+y; +} + +void main() { + println("This program prints 7 7"); + println(identity(7)); + println(add(3, 4)); +} + diff --git a/data/test8.c b/data/test8.c new file mode 100644 index 0000000..df0f2ec --- /dev/null +++ b/data/test8.c @@ -0,0 +1,14 @@ + +int add(int x, int y) { + return x+y; +} + +int add2(int x, int y) { + return add(add(x,y),1); +} + +void main() { + println("This program prints 7"); + println(add2(2, 4)); +} + diff --git a/data/test9.c b/data/test9.c new file mode 100644 index 0000000..1aacb59 --- /dev/null +++ b/data/test9.c @@ -0,0 +1,27 @@ +void main() { + int a; + a = 3; + println("This program prints [1..5] correct."); + if (a < 4) { + println("1 correct"); + } + if (a > 4) { + println("2 not correct"); + } + if (a > 4) { + println("2 not correct"); + } else { + println("2 correct"); + } + if (a <= 3) { + println("3 correct"); + } + if (a == 3) { + println("4 correct"); + } + if (a >= 4) { + println("5 not correct"); + } else { + println("5 correct"); + } +} |