pxasme/main_test.go
2023-12-09 16:12:45 +13:00

46 lines
928 B
Go

package main
import (
"io/ioutil"
"strings"
"testing"
)
func TestCompile(t *testing.T) {
// @ref https://gist.github.com/armicron/e891709ce8893df2fd5fc74c846dcf20
const src = `
section .data
$msg = sz "Hello, world\n"
$filename = sz "test.txt"
$fd = u64 0
section .text
global _start: ;tell linker entry point
mov rdi, &$filename
mov rsi, 66 ;O_CREAT = 0102o (man open)
mov rdx, 438 ;umode_t = 0666 octal
mov rax, 2
syscall
mov $fd, rax
mov rdx, 13 ;message strlen
mov rsi, &$msg ;message to write
mov rdi, $fd ;file descriptor
mov rax, 1 ;system call number (sys_write)
syscall ;call kernel
mov rdi, $fd
mov rax, 3 ;sys_close
syscall
mov rax, 60 ;system call number (sys_exit)
syscall ;call kernel
`
assemble(strings.NewReader(src), ioutil.Discard)
}