【发布时间】:2020-10-26 03:46:01
【问题描述】:
大家好,我正在尝试编写这段代码来检查字符是否在输入的字符串中。这是我的代码
我已经编写了打印语句来查看我的程序是如何运行的,但它完全没有打印任何内容。
extern getchar
extern printf
extern strlen
extern strchr
SECTION .data
string1: db 0,0,0,0,0,0,0,0,0,0,0,0
string2: db "it is there",10,0
string3: db "not there",10,0
string4: db "welp",10,0
char: db "t",10,0
count: dq 12
forcount: dq 12
fmt: db "%s", 10, 0
;fmt2: db "%s", 10, 0
SECTION .text
global main
main:
SECTION .text
global main
main:
sub rsp, 32 ; shadow space
mov rdi, string1 ; printing to
cld ; clear direction flag
.while:
cmp qword [count], 0 ; only get a char while counter is > 0
jne .continue
jmp .done
.continue:
mov rax, 0 ; clear rax before we get a char
call getchar
cmp eax, 10 ; newline
jne .continue2 ; stop collecting on new lines
jmp .done
.continue2:
stosb ; puts al into [rdi] and then increments rdi
sub qword [count], 1
jmp .while
.done:
mov byte [rdi+1], 0 ; don't forget to 0 terminate your strings
;lea rdx, [string1] ;it is here so fa
;lea rcx, [fmt]
;call printf
lea rsi, [string1]
lea rcx, [string1]
call strlen
lea rcx, [rax - 1] ; we need to decrement rax by 1 since strings are 0 indexed
add rsi, rcx ; index to end of string (- 1)
std ; auto decrement rsi
mov rdx, [string1]
lea rcx, [fmt] ; a fmt string containing %lld
call printf
;using it
mov rcx, string1
mov rdx,[char]
call strchr
sub rax, rcx
cmp rax, 0x00
je .no
jne .yes
jmp .welp
.yes:
mov rdx, [string2]
lea rcx, [fmt] ; a fmt string containing %lld
call printf
.no:
mov rdx, [string3]
lea rcx, [fmt] ; a fmt string containing %lld
call printf
.welp:
mov rdx, [string4]
lea rcx, [fmt] ; a fmt string containing %lld
call printf
我已经写了**所有这些代码**并且它没有打印出来。有人可以告诉我我在这里做错了什么吗?如果你想让我改写问题,请告诉我
【问题讨论】: