├── LICENSE ├── Maths.go ├── README.md ├── add.s ├── div.s ├── mul.s └── sub.s /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 EvilBytecode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to use the Software for educational and authorized cybersecurity research purposes only, subject to the following conditions: 7 | 8 | The above copyright notice, this permission notice, and the following disclaimer shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS (INCLUDING EvilBytecode) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 12 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE, COPYING, DOWNLOADING, OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | DISCLAIMER: I, EvilBytecode, release this project strictly for educational, academic, and authorized cybersecurity research purposes. 15 | By accessing, downloading, copying, using, or modifying this software, you agree to these terms. 16 | You must obtain explicit written permission from system owners before conducting any testing using this software. 17 | Unauthorized use, distribution, or deployment of this software against any third party, device, network, or system without prior consent is strictly forbidden and illegal. 18 | I, EvilBytecode, disclaim all responsibility, liability, or consequences arising from any misuse, illegal activities, damages, or losses resulting from this software. -------------------------------------------------------------------------------- /Maths.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func add(x, y int64) int64 6 | func sub(x, y int64) int64 7 | func mul(x, y int64) int64 8 | func div(x, y int64) int64 9 | 10 | func main() { 11 | fmt.Println("Add: ", add(10, 5)) 12 | fmt.Println("Subtract: ", sub(10, 5)) 13 | fmt.Println("Multiply: ", mul(10, 5)) 14 | fmt.Println("Divide: ", div(10, 5)) 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go-Assembly 2 | Example how to use Assembly in Go. 3 | 4 | ## Overview 5 | This project includes assembly routines for the following operations: 6 | 7 | - Addition 8 | - Subtraction 9 | - Multiplication 10 | - Division 11 | 12 | ### Assembly Routines 13 | 14 | Each arithmetic operation (addition, subtraction, multiplication, and division) is implemented as an assembly routine. These routines are written in x86-64 assembly language and perform the following steps: 15 | 16 | 1. **Load Operands:** The input values (operands) are loaded from the Go calling convention's frame pointer (FP) into registers. 17 | 2. **Perform Operation:** The specified arithmetic operation is performed using the appropriate assembly instructions. 18 | 3. **Store Result:** The result of the operation is stored back to the memory location designated for the return value. 19 | 4. **Return:** The routine returns control to the calling Go function. 20 | 21 | ### Go Functions 22 | 23 | In the Go code, each assembly routine is declared as an external function. This allows the Go program to call the assembly routines as if they were regular Go functions. The Go functions for addition, subtraction, multiplication, and division take two `int64` arguments and return an `int64` result. 24 | 25 | ### Main Program 26 | 27 | The main Go program demonstrates the usage of the assembly routines by calling each function with example inputs and printing the results. This illustrates how the Go program interacts with the assembly code to perform arithmetic operations. 28 | 29 | 30 | ### You cant run this directly with ```go run maths.go``` or build it ```go build maths.go```, so do this : ```go mod init Maths``` / ```go build .``` 31 | 32 | 33 | ## License 34 | This project is licensed under the MIT License. See the LICENSE file for details. -------------------------------------------------------------------------------- /add.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·add(SB), NOSPLIT, $0-24 4 | MOVQ x+0(FP), BX 5 | MOVQ y+8(FP), BP 6 | ADDQ BP, BX 7 | MOVQ BX, ret+16(FP) 8 | RET 9 | -------------------------------------------------------------------------------- /div.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·div(SB), NOSPLIT, $0-24 4 | MOVQ x+0(FP), AX 5 | MOVQ y+8(FP), CX 6 | CQO 7 | IDIVQ CX 8 | MOVQ AX, ret+16(FP) 9 | RET 10 | -------------------------------------------------------------------------------- /mul.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·mul(SB), NOSPLIT, $0-24 4 | MOVQ x+0(FP), BX 5 | MOVQ y+8(FP), BP 6 | IMULQ BP, BX 7 | MOVQ BX, ret+16(FP) 8 | RET 9 | -------------------------------------------------------------------------------- /sub.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·sub(SB), NOSPLIT, $0-24 4 | MOVQ x+0(FP), BX 5 | MOVQ y+8(FP), BP 6 | SUBQ BP, BX 7 | MOVQ BX, ret+16(FP) 8 | RET 9 | --------------------------------------------------------------------------------