Endlosschleife beim Schreiben einer einfachen Subroutine zur Ausgabe eines Strings ohne Stack in x86-64Linux

Linux verstehen
Anonymous
 Endlosschleife beim Schreiben einer einfachen Subroutine zur Ausgabe eines Strings ohne Stack in x86-64

Post by Anonymous »

Ich hatte eine Unterroutine zum dynamischen Drucken eines Strings, ohne die Länge des Strings manuell im x86-64-Intel-Stil aufzulisten, durch folgenden Code (mit Stack) :-

Code: Select all

section .data
output1 db "hello world",10,0
output2 db "hello world again",10,0

section .bss

section .text
global _start

_start:
mov rax,output1
call _output

mov rax,output2
call _output

call _exit

_output:
_output_setup:
push rax
mov rbx, 0

_output_length_loop:
inc rax
inc rbx

mov cl,[rax]

cmp cl, 0
jne _output_length_loop

_output_output:
mov rax, 1
mov rdi, 1
pop rsi
mov rdx, rbx
syscall
ret

_exit:
mov rax, 60
mov rdi, 0
syscall
ret
aber ich wollte die Unterroutine ohne Stapel, also habe ich versucht, die Unterroutine so zu schreiben, dass sie dasselbe ohne Verwendung des Stapels macht, also habe ich Folgendes getan:-

Code: Select all

section .data
output1 db "print this string",10,0
output2 db "print this string again",10,0

section .text
global _start

_start:
mov rcx,output1
call _output
mov rcx,output2
call _output
call _exit

_output:
_output_setup:
mov rbx,0

_output_length_loop:
inc rbx
inc rcx

mov dl,[rcx]

cmp dl,0
jne _output_length_loop

_output_output:
mov rax,0
mov rdi,0
mov rsi,rcx
mov rdx,rbx
syscall
ret

_exit:
mov rax,60
mov rdi,0
syscall
ret
Es funktionierte ohne Fehler, aber als ich die ausführbare Datei ausführte, blieb es aus irgendeinem Grund hängen, vermutlich hat es aus irgendeinem Grund eine Endlosschleife erstellt, also hatte ich von einem Tool namens GDB zum Debuggen gehört, aber um ehrlich zu sein, war es ein Chaos für mich, aber ich habe eine zeilenweise Registeranalyse durchgeführt, konnte aber keinen Grund für die obige
meine zeilenweise Analyse ermitteln:-

Code: Select all

rcx     rbx     dl_
_start
b1                                                   - mov rcx, output1
- call _output

_output
0                        - mov rbx,0

_output_loop_length -0
1                        - inc rbx
ib1                          - inc rcx
p                    - mov dl,[rcx]
- cmp dl,0 (p != 0)
- jne _output_length_loop

_output_loop_length -1
2                        - inc rbx
ib1                          - inc rcx
r                    - mov dl,[rcx]
- cmp dl,0 (p != 0)
- jne _output_length_loop

...

_output_loop_length -2
3                        - inc rbx
ib1                          - inc rcx
0                            - mov dl,[rcx]
- cmp dl,0 (p == 0)
- jne _output_length_loop

...
b1 steht für Init-Byte

i vor b1 steht für erhöhte Position des Init-Bytes
Ich vermute, dass „inc rcx“ irgendwie eine Endlosschleife erzeugt, bin mir aber nicht sicher, wieso ich außerdem Unklarheiten in Bezug auf die entsprechende Zeile habe.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post