Skip to content

Commit

Permalink
fix null termination, change mov WORD to mov BYTE (was not the right …
Browse files Browse the repository at this point in the history
…hex code)

fmt
  • Loading branch information
Eliyaan committed Feb 16, 2025
1 parent d0a74f7 commit 3e8133b
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions vlib/v/gen/native/amd64.v
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ fn (mut c Amd64) mov_store(regptr Amd64Register, reg Amd64Register, size Size) {
}
c.g.write8(if size == ._8 { i32(0x88) } else { i32(0x89) })
c.g.write8(i32(reg) % 8 * 8 + i32(regptr) % 8)
c.g.println('mov [${regptr}], ${reg}')
c.g.println('mov [${regptr}], ${reg} ; size:${size}bits')
}

fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) {
Expand Down Expand Up @@ -3536,10 +3536,7 @@ fn (mut c Amd64) convert_int_to_string(a Register, b Register) {
c.div_reg(.rax, .rbx) // rax will be the result of the division
c.add8(.rdx, i32(`0`)) // rdx is the remainder, add 48 to convert it into it's ascii representation

c.g.write8(0x66)
c.g.write8(0x89)
c.g.write8(0x17)
c.g.println('mov BYTE PTR [rdi], rdx')
c.mov_store(.rdi, .rdx, ._8)

// go to the next character
c.inc(.rdi)
Expand All @@ -3555,7 +3552,6 @@ fn (mut c Amd64) convert_int_to_string(a Register, b Register) {
c.g.labels.addrs[loop_label] = loop_start

// null terminate the string
c.inc(.rdi)
c.g.write8(0xc6)
c.g.write8(0x07)
c.g.write8(0x0)
Expand Down

0 comments on commit 3e8133b

Please sign in to comment.