fix program

This commit is contained in:
sfja 2026-01-26 21:33:55 +01:00
parent 8cb0ac6070
commit 3477bb5888
2 changed files with 22 additions and 14 deletions

View File

@ -66,7 +66,6 @@ key_press_int:
mov [rsp], r1
add rsp, 2
;call print_char
call print_u16
sub rsp, 2
@ -112,35 +111,44 @@ print_u16:
mov rbp, rsp
mov r1, [rbp-6] ; value to print
mov r4, 0 ; place index
mov r2, 0 ; place index
jmp .digits_cond
.digits_body:
mov r2, .places
add r2, r4
mov r2, [r2] ; place
mov r3, .places
add r3, r2
mov r3, [r3] ; place
mov r3, 0 ; place occurences
mov r4, 0 ; place occurences
jmp .place_cond
.place_body:
add r3, 1
sub r1, r2
add r4, 1
sub r1, r3
.place_cond:
cmp r2, r1
cmp r3, r1
mov r0, rfl
and r0, fl_eq | fl_lt
jnz r0, .place_body
mov r0, r3
mov r0, r4
add r0, 48
add rsp, 4
mov [rsp-4], r1
mov [rsp-2], r2
mov [rsp], r0
add rsp, 2
call print_char
sub rsp, 2
add r4, 2
mov r2, [rsp-2]
mov r1, [rsp-4]
sub rsp, 4
add r2, 2
.digits_cond:
cmp r4, 10
cmp r2, 10
mov r0, rfl
and r0, fl_lt
jnz r0, .digits_body

View File

@ -279,7 +279,7 @@ int VM::run_instruction()
auto ins = InsReader(*this);
auto op = static_cast<Op>(ins.to_u16() & 0b11'1111);
std::println(
" [{: >2x}]: 0x{:04x} {: <6} {:04b} {:04b} {:04b} {:04b} {:04x}",
" [{: >3x}]: 0x{:04x} {: <6} {:04b} {:04b} {:04b} {:04b} {:04x}",
ip,
ins.to_u16(),
op_str(op),
@ -315,7 +315,7 @@ int VM::run_instruction()
"rfl"sv,
"rip"sv,
};
std::println(" {: <3} | {:04x} {: 5}",
std::println(" {: <3} | {:04x} {: >5}",
reg_strs[reg],
this->reg(static_cast<Reg>(reg)),
this->reg(static_cast<Reg>(reg)));