免责声明:我是初学者,这是我见过的最糟糕的语言
目标是解码消息。 每个字符都编码为 8 个字节
字符和金额是正确的,但由于某种原因我无法获得正确的索引。 通过索引,我可以转到需要从 $message 打印的字符的下一个地址
这不仅仅是一些分段错误,所以我真的不明白为什么我没有得到正确的索引值。现在我得到:
“呵呵
l!olred”而不是“Hello world!”
decode:
pushq %rbp
movq %rsp, %rbp
pushq %rdi
pushq $4 # 16 Stack allignment
movq (%rdi), %rax # Load 8-byte message from address in %rdi
movb %al, %sil # Move the least significant byte of %rax to %sil
shr $8, %rax # Shift %rax right by 8 bits
movb %al, %bl # Move the least significant byte of %rax to %bl
shr $8, %rax # Shift %rax right by 8 bits
.loop:
cmpl $0, %eax
je .finish
movq $String, %rdi # Move the format string to %rdi
call printf # Print the character
dec %bl # Decrement the "amount" counter
cmpb $1, %bl # Compare %bl (amount) with 1
jg .loop
popq %rdi
popq %rdi # Remove 16 bytes
imull $8, %eax # Multiply the index by 8 (8 byte memory blocks)
addq %rax, %rdi
call decode
.finish:
movq %rbp, %rsp
popq %rbp
ret
main:
pushq %rbp # Push the base pointer (and align the stack)
movq %rsp, %rbp # Copy stack pointer value to base pointer
movq $MESSAGE, %rdi # First parameter: address of the message
call decode # Call decode
popq %rbp # Restore base pointer location
movq $0, %rdi # Load program exit code
call exit # Exit the program
每个字符索引是一个字节= 8 位。 将字节索引增加一个字节,而不是加倍 8。