From b13b42d56f6e133a497ff4c7413e1bbd0268bc76 Mon Sep 17 00:00:00 2001 From: Luke Peterson <7110561+LukePeterson@users.noreply.github.com> Date: Tue, 28 May 2024 09:25:33 +1000 Subject: [PATCH] feat(README): adds code quality badges to README.md --- README.md | 1 + assembler/assembler.go | 10 ++++------ assembler/instructions.go | 7 +++---- assembler/tokeniser.go | 9 ++------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 9e97972..033ffbc 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ What good is [an 8080 CPU emulator](https://github.com/lukepeterson/go8080cpu) w This project takes an input string, tokenises the string into a slice of tokens, then parses those tokens, converting each to a valid 8080 opcode. [![Tests](https://github.com/lukepeterson/go8080assembler/actions/workflows/go.yml/badge.svg)](https://github.com/lukepeterson/go8080assembler/actions/workflows/go.yml) +![Go Report Card](https://goreportcard.com/badge/github.com/lukepeterson/go8080assembler) # Features diff --git a/assembler/assembler.go b/assembler/assembler.go index 796349b..90f3a39 100644 --- a/assembler/assembler.go +++ b/assembler/assembler.go @@ -1,3 +1,4 @@ +// Package assembler provides functions for assembling Intel 8080 CPU assembler commands. package assembler import ( @@ -6,6 +7,7 @@ import ( "strings" ) +// Assembler stores our assembled bytecode type Assembler struct { ByteCode []byte } @@ -77,10 +79,7 @@ func (a *Assembler) parseLine(line string) error { return nil } -// parseHex takes a string with an H suffix or 0x prefix and parses it into a 16 bit integer, -// returning the result as two int8s. This has a nice side effect of being able to take -// a one byte string and also returning the result as two 8bit integers, which is -// required for our 2 byte instructions. For example: "4AH" -> 0x00, 0x4A +// parseHex takes a string with an H suffix or 0x prefix and parses it into a 16 bit integer, returning the result as two int8s. This has a nice side effect of being able to take a one byte string and also returning the result as two 8bit integers, which is required for our 2 byte instructions. For example: "4AH" -> 0x00, 0x4A func parseHex(token string) (uint8, uint8, error) { token = strings.TrimSuffix(token, "H") token = strings.TrimPrefix(token, "0x") @@ -95,8 +94,7 @@ func parseHex(token string) (uint8, uint8, error) { return highByte, lowByte, nil } -// Assemble takes a newline separated string of code, parses the input into tokens, -// and then converts each instruction to a valid opcode from the instructionSet. +// Assemble takes a newline separated string of code, parses the input into tokens, and then converts each instruction to a valid opcode from the instructionSet. func (a *Assembler) Assemble(code string) error { lines := strings.Split(code, "\n") for _, line := range lines { diff --git a/assembler/instructions.go b/assembler/instructions.go index 4357c5e..c84c509 100644 --- a/assembler/instructions.go +++ b/assembler/instructions.go @@ -1,15 +1,14 @@ package assembler +// Instruction stores a single instruction, made up of a one byte Opcode and an instruction length. type Instruction struct { Opcode byte Length int } -// Grouped by instruction set group as per "Table 2. Instruction Set Summary", -// in the Intel 8080A 8-BIT N-CHANNEL MICROPROCESSOR datasheet. +// Grouped by instruction set group as per "Table 2. Instruction Set Summary", in the Intel 8080A 8-BIT N-CHANNEL MICROPROCESSOR datasheet. // Opcode = the 1 byte hexadecimal representation of the instruction for the 8080 -// Length = how many bytes in total the instruction has (more succintly, how many n-1 bytes _after_ -// the opcode to interpret as the operand) +// Length = how many bytes in total the instruction has (more succintly, how many n-1 bytes _after_ the opcode to interpret as the operand) var instructionSet = map[string]Instruction{ // MOVE, LOAD AND STORE "MOV A,B": {Opcode: 0x78, Length: 1}, diff --git a/assembler/tokeniser.go b/assembler/tokeniser.go index 9775257..9d4174f 100644 --- a/assembler/tokeniser.go +++ b/assembler/tokeniser.go @@ -5,11 +5,7 @@ import ( "strings" ) -// tokenise takes a line of code as an input, removes extra spacing/commas, -// and then returns the opcode and operands as separate strings. The most -// important feature of this function is the ability to distinguish between -// single and multi-byte instructions and treat them as one. For example: -// "MOV B, B" (one byte) and "MVI B" (two bytes). +// tokenise takes a line of code as an input, removes extra spacing/commas, and then returns the opcode and operands as separate strings. This function can also distinguish between single and multi-byte instructions and treat them as one. For example: "MOV B, B" (one byte) and "MVI B" (two bytes). func tokenise(line string) ([]string, error) { line = normalise(line) @@ -28,8 +24,7 @@ func tokenise(line string) ([]string, error) { return tokens, nil } -// normalise takes an input string, converts it to upper case, strips out extra spaces, -// and makes all comma formatting consistent, helping us match against out opcode map. +// normalise takes an input string, converts it to upper case, strips out extra spaces, and makes all comma formatting consistent, helping us match against out opcode map. func normalise(line string) string { line = strings.ToUpper(line)