Печать строки ввода пользователя с использованием NASM - PullRequest
0 голосов
/ 30 октября 2019

Это говорит о том, что строка 1 (ноль).
Я не уверен, как распечатать строку, которую вводит пользователь.
Она должна быть в моей "равной" подпрограмме для сравнения строк, чтобы увидеть,они содержат одинаковое количество символов.

  %include "io.inc"

%define STRING_SIZE 11

section .data
    prompt1        db "String 1: ",10,0
    prompt2         db "String 2: ",10,0

    inputStr1       db "%s",0
    inputStr2       db "%s",0

    output1         db "String 1 is %s ",10,0
    output2         db "String 2 is %s ",10,0
    output3         db "%s does not equal %s ",10,0
    output4         db "Copying String 1 over String 2 ",10,0
    output5         db "String 1 is %s and String 2 is %s ",10,0
    output6         db "Making String 2 a substring is String 1 ",10,0
    output7         db "String 1 is %s and String 2 is %s ",10,0

section .bss
    string1     resb STRING_SIZE
    string2     resb STRING_SIZE

section .text
global CMAIN
extern printf, scanf
CMAIN:
    ;write your code here
    enter 0,0

    ; Get the two strings from the user
    push    prompt1     ; Prompt the user for the first string
    call    printf
    add     esp,4
    push    string1     ; Capture the first string
    push    inputStr1
    call    scanf
    add     esp,8
    push    prompt2     ; Prompt the user for the second string
    call    printf
    add     esp,4
    push    string2     ; Capture the second string
    push    inputStr2
    call    scanf
    add     esp,8

    ; call equal program
    push    string2     ; call equal(string1, string2)
    push    string1
    call    equal
    add     esp,8       ; remove 8 bytes from the stack (string1 and string2 are each 4 bytes)

    leave
    xor eax, eax
    ret

equal:
    enter   0,0
    push    esi             ; push these esi,edi,ebx to preserve their values
    push    edi
    push    ebx

    xor     eax,eax
    mov     esi,[ebp+8]     ; esi = string1
    mov     edi,[ebp+12]    ; edi = string2
    mov     ecx,10          ; ecx = 10  
    repe    cmpsb           ; compare esi and edi until they are different, or ecx is 0
    setz    al              ; al = 1, if equal. al = 0, if strings are different   

    push    esi
    push    output1
    call    printf
    add     esp,8

    push        edi
    push        output2
    call        printf
    add     esp,8

    pop     ebx             ; pop ebx,edi,esi to restore their original values
    pop     edi
    pop     esi
    leave
    ret
...