all far call and ret

This commit is contained in:
sfja 2025-03-31 23:37:50 +02:00
parent 827c593712
commit 05793ad4ae
4 changed files with 106 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include "asm.h"
#include "common/arch.h"
#include "common/fmt_binary.h"
#include "common/op_str.h"
#include <stdbool.h>
#include <stddef.h>
@ -535,11 +536,69 @@ uint16_t assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
ADD_LABEL(op1);
break;
}
case LineTy_CallFar_Reg_Reg: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
add_op1_reg(&ins, op1);
ins |= (op2 << 7) & 0x7;
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_CallFar_Reg_Imm: {
uint16_t op1 = line->op1.reg;
uint16_t op2 = line->op2.imm;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
ins |= 1 << 14;
add_op1_reg(&ins, op1);
out[ip++] = (uint16_t)ins;
out[ip++] = op2;
break;
}
case LineTy_CallFar_Imm_Reg: {
uint16_t op1 = line->op1.imm;
uint16_t op2 = line->op2.reg;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
set_is_imm(&ins);
ins |= (op2 << 7) & 0x7;
out[ip++] = (uint16_t)ins;
out[ip++] = op1;
break;
}
case LineTy_CallFar_Imm_Imm: {
uint16_t op1 = line->op1.imm;
uint16_t op2 = line->op2.imm;
uint32_t ins = Op_Jmp;
ins |= 1 << 13;
ins |= 1 << 14;
set_is_imm(&ins);
out[ip++] = (uint16_t)ins;
out[ip++] = op2;
out[ip++] = op1;
break;
}
case LineTy_Ret: {
uint32_t ins = Op_Ret;
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_RetFar: {
uint32_t ins = Op_Ret;
ins |= 1 << 6;
out[ip++] = (uint16_t)ins;
break;
}
case LineTy_Lit_Reg: {
uint16_t op1 = line->op1.reg;

View File

@ -47,7 +47,12 @@ typedef enum {
LineTy_Call_Reg,
LineTy_Call_Imm,
LineTy_Call_Label,
LineTy_CallFar_Reg_Reg,
LineTy_CallFar_Reg_Imm,
LineTy_CallFar_Imm_Reg,
LineTy_CallFar_Imm_Imm,
LineTy_Ret,
LineTy_RetFar,
LineTy_Lit_Reg,
LineTy_Lit_Imm,
LineTy_Lit_Label,
@ -154,7 +159,12 @@ Line s_in_i(Reg dst_reg, uint16_t op1_imm);
Line s_call_r(Reg op1_reg);
Line s_call_i(uint16_t op1_imm);
Line s_call_l(int op1_label);
Line s_callf_r_r(Reg op1_reg, Reg op2_reg);
Line s_callf_r_i(Reg op1_reg, uint16_t op2_imm);
Line s_callf_i_r(uint16_t op1_imm, Reg op2_reg);
Line s_callf_i_i(uint16_t op1_imm, uint16_t op2_imm);
Line s_ret(void);
Line s_retf(void);
Line s_lit_r(Reg op1_reg);
Line s_lit_i(uint16_t op1_imm);
Line s_lit_l(int op1_label);

View File

@ -325,10 +325,46 @@ Line s_call_l(int op1_label)
.op1 = (Ex) { .label = op1_label },
};
}
Line s_callf_r_r(Reg op1_reg, Reg op2_reg)
{
return (Line) {
.ty = LineTy_CallFar_Reg_Reg,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_callf_r_i(Reg op1_reg, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_CallFar_Reg_Imm,
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
.op2 = (Ex) { .imm = op2_imm },
};
}
Line s_callf_i_r(uint16_t op1_imm, Reg op2_reg)
{
return (Line) {
.ty = LineTy_CallFar_Imm_Reg,
.op1 = (Ex) { .imm = op1_imm },
.op2 = (Ex) { .reg = (uint16_t)op2_reg },
};
}
Line s_callf_i_i(uint16_t op1_imm, uint16_t op2_imm)
{
return (Line) {
.ty = LineTy_CallFar_Imm_Imm,
.op1 = (Ex) { .imm = op1_imm },
.op2 = (Ex) { .imm = op2_imm },
};
}
Line s_ret(void)
{
return (Line) { .ty = LineTy_Ret };
}
Line s_retf(void)
{
return (Line) { .ty = LineTy_RetFar };
}
Line s_lit_r(Reg op1_reg)
{
return (Line) {

View File

@ -1,4 +1,4 @@
#include "asm/asm.h"
#include "common/fmt_binary.h"
#include "common/op_str.h"
#include "common/video_character_display.h"
#include "vm.h"