Added memory address patching

This commit is contained in:
Eduard Urbach 2023-10-29 12:24:40 +01:00
parent 6f097c9eee
commit 23e8b67e88
Signed by: eduard
GPG key ID: 49226B848C78F6C8
9 changed files with 98 additions and 35 deletions

View file

@ -2,9 +2,7 @@ package asm
import (
"fmt"
"io"
"git.akyoto.dev/cli/q/src/asm/x64"
"git.akyoto.dev/cli/q/src/register"
)
@ -14,16 +12,7 @@ type Instruction struct {
Source register.ID
Destination register.ID
Number uint64
}
// Write writes the machine code of the instruction.
func (x *Instruction) Write(w io.ByteWriter) {
switch x.Mnemonic {
case MOV:
x64.MoveRegNum32(w, uint8(x.Destination), uint32(x.Number))
case SYSCALL:
x64.Syscall(w)
}
Data []byte
}
// String returns the assembler representation of the instruction.
@ -31,6 +20,8 @@ func (x *Instruction) String() string {
switch x.Mnemonic {
case MOV:
return fmt.Sprintf("%s %s, %x", x.Mnemonic, x.Destination, x.Number)
case MOVDATA:
return fmt.Sprintf("%s %s, %v", x.Mnemonic, x.Destination, x.Data)
case SYSCALL:
return x.Mnemonic.String()
default: