NASM перебирает байты - PullRequest
       10

NASM перебирает байты

1 голос
/ 26 января 2012

В настоящее время я пытаюсь перебрать каждый байт в буфере (чтение из файла) и сравнить его, чтобы увидеть, является ли какой-либо из них пробел, и записать их в STDOUT. По какой-то причине программа компилируется и работает нормально, но выдает нулевой вывод.

section .data
   bufsize dw      1024

section .bss
   buf     resb    1024
section  .text
  global  _start

_start:
    ; open the file provided form cli in read mode
    mov edi, 0
    pop   ebx
    pop   ebx
    pop   ebx
    mov   eax,  5
    mov   ecx,  0 
    int   80h
    ; write the contents in to the buffer 'buf'
    mov     eax,  3
    mov     ebx,  eax
    mov     ecx,  buf
    mov     edx,  bufsize
    int     80h

    ; write the value at buf+edi to STDOUT 
    mov     eax,  4
    mov     ebx,  1
    mov     ecx,  [buf+edi]
    mov     edx, 1
    int     80h
    ; if not equal to whitespace, jump to the loop
    cmp byte [buf+edi], 0x20
    jne loop

loop:
    ; increment the loop counter
    add     edi, 1
    mov     eax,  4
    mov     ebx,  1
    mov     ecx,  [buf+edi]
    int     80h
    ; compare the value at buf+edi with the HEX for whitespace
    cmp byte [buf+edi], 0x20
    jne loop

; exit the program
mov   eax,  1
mov   ebx,  0 
int   80h

1 Ответ

1 голос
/ 26 января 2012

Основная проблема состояла в том, что я не дал адрес bufsize ([bufsize]), также у циклов были некоторые проблемы.

Вот исправленная версия, спасибо всем за ваш вклад.

section .data
   bufsize dd      1024

section .bss
   buf:     resb    1024
section  .text
  global  _start

_start:
    ; open the file provided form cli in read mode
    mov edi, 0
    pop   ebx
    pop   ebx
    pop   ebx
    mov   eax,  5
    mov   ecx,  0
    int   80h
    ; write the contents in to the buffer 'buf'
    mov     eax,  3
    mov     ebx,  eax
    mov     ecx,  buf
    mov     edx,  [bufsize]
    int     80h

    ; write the value at buf+edi to STDOUT
    ; if equal to whitespace, done
loop:
    cmp byte [buf+edi], 0x20
    je done
    mov     eax,  4
    mov     ebx,  1
    lea     ecx,  [buf+edi]
    mov     edx,  1
    int     80h
    ; increment the loop counter
    add     edi, 1
    jmp loop
done:
; exit the program
mov   eax,  1
mov   ebx,  0
int   80h
...