gpt4 book ai didi

linux - 先前输出后控制台输出不正确

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:09 25 4
gpt4 key购买 nike

任务:将数字以十六进制形式输出到控制台。之后打印一些字符串(让它成为“数字之后的字符串”)。第一部分成功,但第二部分不成功。

  • 输入的数字通过num标签存储在内存中。
  • 字符串通过标签存储在内存中。
  • 字符串长度 - 行数

代码:

global _start

section .data
num db 01111110b
temp db 0

line db 10, "String after num", 10
lines equ $-line

section .text
_start:
call write_hex ; write num in hex format

mov eax, 4 ; write "Hello world!"
mov ebx, 1 ;
mov ecx, line ;
mov edx, lines ;
int 80H ;

mov eax, 1 ; exit
xor ebx, ebx
int 80H

write_hex:
mov eax, [num]
mov [temp], eax
shr byte [num], 4
call to_hex_digit
call write_digit

mov eax, [temp]
mov [num], eax

and byte [num], 1111b
call to_hex_digit
call write_digit
ret

to_hex_digit:
add [num], byte '0'
cmp [num], byte '9'
jle end
add [num], byte 7
end: ret

write_digit:
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 1
int 80H
ret

输出:

output

感谢您的帮助。

最佳答案

我使用了无效的寄存器来存储临时值。我将与 temp 一起工作的寄存器从 eax 替换为 al。请参阅 Jester 的回答。

关于linux - 先前输出后控制台输出不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52795272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com