From 13812cc1741729cca7f714be89500da647e09e5c Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 17 Jun 2018 13:02:17 -0400 Subject: feat(mips.html.markdown): Added description and comments for MIPS --- mips.html.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 mips.html.markdown diff --git a/mips.html.markdown b/mips.html.markdown new file mode 100644 index 00000000..b3be1bb8 --- /dev/null +++ b/mips.html.markdown @@ -0,0 +1,16 @@ +--- +language: "MIPS" +filename: MIPS.mips +contributors: + - ["Stanley Lim", "https://github.com/Spiderpig86"] +--- + +The MIPS (Microprocessor without Interlocked Pipeline Stages) Assembly language is designed to work with the MIPS microprocessor paradigm designed by J. L. Hennessy in 1981. These RISC processors are used in embedded systems such as gateways and routers. + +[Read More](https://en.wikipedia.org/wiki/MIPS_architecture) + +```assembly +# Comments are denoted with a '#' + +# Everything that occurs after a '#' will be ignored by the assembler's lexer. +``` \ No newline at end of file -- cgit v1.2.3 From 86b8304bc28abab2c1565710deaced66e7a72606 Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 24 Jun 2018 14:00:07 -0400 Subject: feat(mips.html.markdown): Added info for data section --- mips.html.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mips.html.markdown b/mips.html.markdown index b3be1bb8..952cc551 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -13,4 +13,24 @@ The MIPS (Microprocessor without Interlocked Pipeline Stages) Assembly language # Comments are denoted with a '#' # Everything that occurs after a '#' will be ignored by the assembler's lexer. + +# Programs typically contain a .data and .text sections + +.data # Section where data is stored in memory (allocated in RAM), similar to variables in higher level languages + + # Declarations follow a ( label: .type value(s) ) form of declaration + hello_world .asciiz "Hello World\n" # Declare a null terminated string + num1: .word 42 # Integers are referred to as words (32 bit value) + arr1: .word 1, 2, 3, 4, 5 # Array of words + arr2: .byte 'a', 'b' # Array of chars (1 byte each) + buffer: .space 60 # Allocates space in the RAM (not cleared to 0) + + # Datatype sizes + _byte: .byte 'a' # 1 byte + _halfword: .half 53 # 2 bytes + _word: .word 3 # 4 bytes + _float: .float 3.14 # 4 bytes + _double: .double 7.0 # 8 bytes + + ``` \ No newline at end of file -- cgit v1.2.3 From 254879a3be6829fa13d984a73dcda994aa3cd83d Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 24 Jun 2018 14:55:47 -0400 Subject: feat(mips.html.markdown): Added basics of loading and storing instructions --- mips.html.markdown | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/mips.html.markdown b/mips.html.markdown index 952cc551..1c857ba4 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -19,18 +19,47 @@ The MIPS (Microprocessor without Interlocked Pipeline Stages) Assembly language .data # Section where data is stored in memory (allocated in RAM), similar to variables in higher level languages # Declarations follow a ( label: .type value(s) ) form of declaration - hello_world .asciiz "Hello World\n" # Declare a null terminated string - num1: .word 42 # Integers are referred to as words (32 bit value) - arr1: .word 1, 2, 3, 4, 5 # Array of words - arr2: .byte 'a', 'b' # Array of chars (1 byte each) - buffer: .space 60 # Allocates space in the RAM (not cleared to 0) +hello_world .asciiz "Hello World\n" # Declare a null terminated string + num1: .word 42 # Integers are referred to as words (32 bit value) + arr1: .word 1, 2, 3, 4, 5 # Array of words + arr2: .byte 'a', 'b' # Array of chars (1 byte each) + buffer: .space 60 # Allocates space in the RAM (not cleared to 0) # Datatype sizes - _byte: .byte 'a' # 1 byte - _halfword: .half 53 # 2 bytes - _word: .word 3 # 4 bytes - _float: .float 3.14 # 4 bytes - _double: .double 7.0 # 8 bytes + _byte: .byte 'a' # 1 byte + _halfword: .half 53 # 2 bytes + _word: .word 3 # 4 bytes + _float: .float 3.14 # 4 bytes + _double: .double 7.0 # 8 bytes + .align 2 # Memory alignment of data, where number indicates byte alignment in powers of 2. (.align 2 represents word alignment since 2^2 = 4 bytes) + +.text # Section that contains instructions and program logic +.globl _main # Declares an instruction label as global, making it accessible to other files + + _main: # MIPS programs execute instructions sequentially, where this will be executed first + + # Let's print "hello world" + la $a0, hello_world # Load address of string stored in memory + li $v0, 4 # Load the syscall value (indicating type of functionality) + syscall # Perform the specified syscall with the given argument ($a0) + + # Registers (used to hold data during program execution) + # $t0 - $t9 # Temporary registers used for intermediate calculations inside subroutines (not saved across function calls) + # $s0 - $s7 # Saved registers where values are saved across subroutine calls. Typically saved in stack + # $a0 - $a3 # Argument registers for passing in arguments for subroutines + # $v0 - $v1 # Return registers for returning values to caller function + + # Types of load/store instructions + la $t0, label # Copy the address of a value in memory specified by the label into register $t0 + lw $t0, label # Copy a word value from memory + lw $t1, 4($s0) # Copy a word value from an address stored in a register with an offset of 4 bytes (addr + 4) + lb $t2, label # Copy a byte value to the lower order portion of the register $t2 + lb $t2, 0($s0) # Copy a byte value from the source address in $s0 with offset 0 + # Same idea with 'lh' for halfwords + + sw $t0, label # Store word value into memory address mapped by label + sw $t0, 8($s0) # Store word value into address specified in $s0 and offset of 8 bytes + # Same idea using 'sb' and 'sh' for bytes and halfwords. 'sa' does not exist ``` \ No newline at end of file -- cgit v1.2.3 From b3d8f0cdc7eef9659ad2fab04c4047c2851ab381 Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sat, 7 Jul 2018 12:08:10 -0400 Subject: feat(mips.html.markdown): Started working on math --- mips.html.markdown | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mips.html.markdown b/mips.html.markdown index 1c857ba4..b1ef40c4 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -37,7 +37,7 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string .text # Section that contains instructions and program logic .globl _main # Declares an instruction label as global, making it accessible to other files - _main: # MIPS programs execute instructions sequentially, where this will be executed first + _main: # MIPS programs execute instructions sequentially, where the code under this label will be executed firsts # Let's print "hello world" la $a0, hello_world # Load address of string stored in memory @@ -62,4 +62,12 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string sw $t0, 8($s0) # Store word value into address specified in $s0 and offset of 8 bytes # Same idea using 'sb' and 'sh' for bytes and halfwords. 'sa' does not exist +### Math ### + _math: + # Remember to load your values into a register + lw $t0, num # From the data section + li $t0, 5 # Or from an immediate (constant) + li $t1, 6 + add $t2, $t0, $t1 # $t2 = $t0 + $t1 + ``` \ No newline at end of file -- cgit v1.2.3 From 4c025bc12b9a204ff205281b0bd6048ae969140b Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 8 Jul 2018 15:05:27 -0400 Subject: feat(mips.html.markdown): Added mathematical operations and logical operator examples --- mips.html.markdown | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/mips.html.markdown b/mips.html.markdown index b1ef40c4..5e6a9c99 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -65,9 +65,30 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string ### Math ### _math: # Remember to load your values into a register - lw $t0, num # From the data section - li $t0, 5 # Or from an immediate (constant) + lw $t0, num # From the data section + li $t0, 5 # Or from an immediate (constant) li $t1, 6 - add $t2, $t0, $t1 # $t2 = $t0 + $t1 + add $t2, $t0, $t1 # $t2 = $t0 + $t1 + sub $t2, $t0, $t1 # $t2 = $t0 - $t1 + mul $t2, $t0, $t1 # $t2 = $t0 * $t1 + div $t2, $t0, $t1 # $t2 = $t0 / $t1 (Might not be supported in some versons of MARS) + div $t0, $t1 # Performs $t0 / $t1. Get the quotient using 'mflo' and remainder using 'mfhi' + + # Bitwise Shifting + sll $t0, $t0, 2 # Bitwise shift to the left with immediate (constant value) of 2 + sllv $t0, $t1, $t2 # Shift left by a variable amount in register + srl $t0, $t0, 5 # Bitwise shift to the right (does not sign preserve, sign-extends with 0) + srlv $t0, $t1, $t2 # Shift right by a variable amount in a register + sra $t0, $t0, 7 # Bitwise arithmetic shift to the right (preserves sign) + srav $t0, $t1, $t2 # Shift right by a variable amount in a register + + # Bitwise operators + and $t0, $t1, $t2 # Bitwise AND + andi $t0, $t1, 0xFFF # Bitwise AND with immediate + or $t0, $t1, $t2 # Bitwise OR + ori $t0, $t1, 0xFFF # Bitwise OR with immediate + xor $t0, $t1, $t2 # Bitwise XOR + xori $t0, $t1, 0xFFF # Bitwise XOR with immediate + nor $t0, $t1, $t2 # Bitwise NOR ``` \ No newline at end of file -- cgit v1.2.3 From 6f32ec9859005b370994402848547c8a90400de2 Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 8 Jul 2018 15:16:26 -0400 Subject: chore(mips.html.markdown): Fixed formatting of comments --- mips.html.markdown | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/mips.html.markdown b/mips.html.markdown index 5e6a9c99..e40c4b64 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -68,27 +68,27 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string lw $t0, num # From the data section li $t0, 5 # Or from an immediate (constant) li $t1, 6 - add $t2, $t0, $t1 # $t2 = $t0 + $t1 - sub $t2, $t0, $t1 # $t2 = $t0 - $t1 - mul $t2, $t0, $t1 # $t2 = $t0 * $t1 - div $t2, $t0, $t1 # $t2 = $t0 / $t1 (Might not be supported in some versons of MARS) - div $t0, $t1 # Performs $t0 / $t1. Get the quotient using 'mflo' and remainder using 'mfhi' + add $t2, $t0, $t1 # $t2 = $t0 + $t1 + sub $t2, $t0, $t1 # $t2 = $t0 - $t1 + mul $t2, $t0, $t1 # $t2 = $t0 * $t1 + div $t2, $t0, $t1 # $t2 = $t0 / $t1 (Might not be supported in some versons of MARS) + div $t0, $t1 # Performs $t0 / $t1. Get the quotient using 'mflo' and remainder using 'mfhi' # Bitwise Shifting - sll $t0, $t0, 2 # Bitwise shift to the left with immediate (constant value) of 2 - sllv $t0, $t1, $t2 # Shift left by a variable amount in register - srl $t0, $t0, 5 # Bitwise shift to the right (does not sign preserve, sign-extends with 0) - srlv $t0, $t1, $t2 # Shift right by a variable amount in a register - sra $t0, $t0, 7 # Bitwise arithmetic shift to the right (preserves sign) - srav $t0, $t1, $t2 # Shift right by a variable amount in a register + sll $t0, $t0, 2 # Bitwise shift to the left with immediate (constant value) of 2 + sllv $t0, $t1, $t2 # Shift left by a variable amount in register + srl $t0, $t0, 5 # Bitwise shift to the right (does not sign preserve, sign-extends with 0) + srlv $t0, $t1, $t2 # Shift right by a variable amount in a register + sra $t0, $t0, 7 # Bitwise arithmetic shift to the right (preserves sign) + srav $t0, $t1, $t2 # Shift right by a variable amount in a register # Bitwise operators - and $t0, $t1, $t2 # Bitwise AND - andi $t0, $t1, 0xFFF # Bitwise AND with immediate - or $t0, $t1, $t2 # Bitwise OR - ori $t0, $t1, 0xFFF # Bitwise OR with immediate - xor $t0, $t1, $t2 # Bitwise XOR - xori $t0, $t1, 0xFFF # Bitwise XOR with immediate - nor $t0, $t1, $t2 # Bitwise NOR + and $t0, $t1, $t2 # Bitwise AND + andi $t0, $t1, 0xFFF # Bitwise AND with immediate + or $t0, $t1, $t2 # Bitwise OR + ori $t0, $t1, 0xFFF # Bitwise OR with immediate + xor $t0, $t1, $t2 # Bitwise XOR + xori $t0, $t1, 0xFFF # Bitwise XOR with immediate + nor $t0, $t1, $t2 # Bitwise NOR ``` \ No newline at end of file -- cgit v1.2.3 From 119c4172bb4eec083b23a86f784809705276e51a Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 8 Jul 2018 21:16:51 -0400 Subject: chore(mips.html.markdown): Content now wraps at 80 chars --- .vscode/settings.json | 3 ++ mips.html.markdown | 101 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..ae758328 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.rulers": [80, 120], +} \ No newline at end of file diff --git a/mips.html.markdown b/mips.html.markdown index e40c4b64..6a9a7c2a 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -5,7 +5,10 @@ contributors: - ["Stanley Lim", "https://github.com/Spiderpig86"] --- -The MIPS (Microprocessor without Interlocked Pipeline Stages) Assembly language is designed to work with the MIPS microprocessor paradigm designed by J. L. Hennessy in 1981. These RISC processors are used in embedded systems such as gateways and routers. +The MIPS (Microprocessor without Interlocked Pipeline Stages) Assembly language +is designed to work with the MIPS microprocessor paradigm designed by J. L. +Hennessy in 1981. These RISC processors are used in embedded systems such as +gateways and routers. [Read More](https://en.wikipedia.org/wiki/MIPS_architecture) @@ -16,14 +19,18 @@ The MIPS (Microprocessor without Interlocked Pipeline Stages) Assembly language # Programs typically contain a .data and .text sections -.data # Section where data is stored in memory (allocated in RAM), similar to variables in higher level languages +.data # Section where data is stored in memory (allocated in RAM), similar to +variables in higher level languages # Declarations follow a ( label: .type value(s) ) form of declaration hello_world .asciiz "Hello World\n" # Declare a null terminated string - num1: .word 42 # Integers are referred to as words (32 bit value) + num1: .word 42 # Integers are referred to as words + # (32 bit value) + arr1: .word 1, 2, 3, 4, 5 # Array of words arr2: .byte 'a', 'b' # Array of chars (1 byte each) - buffer: .space 60 # Allocates space in the RAM (not cleared to 0) + buffer: .space 60 # Allocates space in the RAM + # (not cleared to 0) # Datatype sizes _byte: .byte 'a' # 1 byte @@ -32,34 +39,62 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string _float: .float 3.14 # 4 bytes _double: .double 7.0 # 8 bytes - .align 2 # Memory alignment of data, where number indicates byte alignment in powers of 2. (.align 2 represents word alignment since 2^2 = 4 bytes) + .align 2 # Memory alignment of data, where + # number indicates byte alignment in + # powers of 2. (.align 2 represents + #word alignment since 2^2 = 4 bytes) -.text # Section that contains instructions and program logic -.globl _main # Declares an instruction label as global, making it accessible to other files +.text # Section that contains instructions + # and program logic +.globl _main # Declares an instruction label as + # global, making it accessible to + # other files - _main: # MIPS programs execute instructions sequentially, where the code under this label will be executed firsts + _main: # MIPS programs execute instructions + # sequentially, where the code under + # this label will be executed firsts # Let's print "hello world" - la $a0, hello_world # Load address of string stored in memory - li $v0, 4 # Load the syscall value (indicating type of functionality) - syscall # Perform the specified syscall with the given argument ($a0) + la $a0, hello_world # Load address of string stored in + # memory + li $v0, 4 # Load the syscall value (indicating + # type of functionality) + syscall # Perform the specified syscall with + # the given argument ($a0) # Registers (used to hold data during program execution) - # $t0 - $t9 # Temporary registers used for intermediate calculations inside subroutines (not saved across function calls) - # $s0 - $s7 # Saved registers where values are saved across subroutine calls. Typically saved in stack - # $a0 - $a3 # Argument registers for passing in arguments for subroutines - # $v0 - $v1 # Return registers for returning values to caller function + # $t0 - $t9 # Temporary registers used for + # intermediate calculations inside + # subroutines (not saved across + # function calls) + + # $s0 - $s7 # Saved registers where values are + # saved across subroutine calls. + # Typically saved in stack + + # $a0 - $a3 # Argument registers for passing in + # arguments for subroutines + # $v0 - $v1 # Return registers for returning + # values to caller function # Types of load/store instructions - la $t0, label # Copy the address of a value in memory specified by the label into register $t0 + la $t0, label # Copy the address of a value in + # memory specified by the label into + # register $t0 lw $t0, label # Copy a word value from memory - lw $t1, 4($s0) # Copy a word value from an address stored in a register with an offset of 4 bytes (addr + 4) - lb $t2, label # Copy a byte value to the lower order portion of the register $t2 - lb $t2, 0($s0) # Copy a byte value from the source address in $s0 with offset 0 + lw $t1, 4($s0) # Copy a word value from an address + # stored in a register with an offset + # of 4 bytes (addr + 4) + lb $t2, label # Copy a byte value to the lower order + # portion of the register $t2 + lb $t2, 0($s0) # Copy a byte value from the source + # address in $s0 with offset 0 # Same idea with 'lh' for halfwords - sw $t0, label # Store word value into memory address mapped by label - sw $t0, 8($s0) # Store word value into address specified in $s0 and offset of 8 bytes + sw $t0, label # Store word value into memory address + # mapped by label + sw $t0, 8($s0) # Store word value into address + # specified in $s0 and offset of 8 bytes # Same idea using 'sb' and 'sh' for bytes and halfwords. 'sa' does not exist ### Math ### @@ -71,16 +106,24 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string add $t2, $t0, $t1 # $t2 = $t0 + $t1 sub $t2, $t0, $t1 # $t2 = $t0 - $t1 mul $t2, $t0, $t1 # $t2 = $t0 * $t1 - div $t2, $t0, $t1 # $t2 = $t0 / $t1 (Might not be supported in some versons of MARS) - div $t0, $t1 # Performs $t0 / $t1. Get the quotient using 'mflo' and remainder using 'mfhi' + div $t2, $t0, $t1 # $t2 = $t0 / $t1 (Might not be + # supported in some versons of MARS) + div $t0, $t1 # Performs $t0 / $t1. Get the quotient + # using 'mflo' and remainder using 'mfhi' # Bitwise Shifting - sll $t0, $t0, 2 # Bitwise shift to the left with immediate (constant value) of 2 - sllv $t0, $t1, $t2 # Shift left by a variable amount in register - srl $t0, $t0, 5 # Bitwise shift to the right (does not sign preserve, sign-extends with 0) - srlv $t0, $t1, $t2 # Shift right by a variable amount in a register - sra $t0, $t0, 7 # Bitwise arithmetic shift to the right (preserves sign) - srav $t0, $t1, $t2 # Shift right by a variable amount in a register + sll $t0, $t0, 2 # Bitwise shift to the left with + # immediate (constant value) of 2 + sllv $t0, $t1, $t2 # Shift left by a variable amount in + # register + srl $t0, $t0, 5 # Bitwise shift to the right (does + # not sign preserve, sign-extends with 0) + srlv $t0, $t1, $t2 # Shift right by a variable amount in + # a register + sra $t0, $t0, 7 # Bitwise arithmetic shift to the right + # (preserves sign) + srav $t0, $t1, $t2 # Shift right by a variable amount + # in a register # Bitwise operators and $t0, $t1, $t2 # Bitwise AND -- cgit v1.2.3 From e566cee6c046fe680c7be0a745d447c3818420d9 Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 8 Jul 2018 21:32:51 -0400 Subject: chore(mips.html.markdown): Fixed minor space issue --- mips.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mips.html.markdown b/mips.html.markdown index 6a9a7c2a..dd7bc7b5 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -1,6 +1,6 @@ --- -language: "MIPS" -filename: MIPS.mips +language: "MIPS Assembly" +filename: MIPS.asm contributors: - ["Stanley Lim", "https://github.com/Spiderpig86"] --- @@ -42,7 +42,7 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string .align 2 # Memory alignment of data, where # number indicates byte alignment in # powers of 2. (.align 2 represents - #word alignment since 2^2 = 4 bytes) + # word alignment since 2^2 = 4 bytes) .text # Section that contains instructions # and program logic -- cgit v1.2.3 From 3315df63f9d28f52d23fd16d907554f1655366e2 Mon Sep 17 00:00:00 2001 From: spiderpig86 Date: Sun, 8 Jul 2018 21:34:28 -0400 Subject: chore(.vscode): Removed config folder --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ae758328..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "editor.rulers": [80, 120], -} \ No newline at end of file -- cgit v1.2.3 From 81f9f0fec80b3c459937dd59be8384433251e3f8 Mon Sep 17 00:00:00 2001 From: Stanley Lim Date: Fri, 20 Jul 2018 10:39:43 -0400 Subject: feat(mips.html.markdown): Added examples for branching and conditionals --- mips.html.markdown | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/mips.html.markdown b/mips.html.markdown index dd7bc7b5..418761bf 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -134,4 +134,68 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string xori $t0, $t1, 0xFFF # Bitwise XOR with immediate nor $t0, $t1, $t2 # Bitwise NOR -``` \ No newline at end of file +## BRANCHING ## + _branching: + # The basic format of these branching instructions typically follow + #