更改汇编代码,我可以使用一些帮助

时间:2019-01-27 13:47:07

标签: arrays ascii nasm

我需要帮助,我需要更改程序以将ASCII“ F”显示为数组的总和。

我不确定该怎么做,并且尝试过并失败了。任何帮助将不胜感激。

section .text
    global _start ;must be declared for linker (ld)
_start: 
    mov eax,3    ; Number bytes to be summed 
    mov ebx,0    ; ebx will store the sum
    mov ecx, x   ; ecx will point to the current element to be summed
top: 
    add ebx, [ecx]
    add ecx, 1      ; Move pointer to next element
    dec eax         ; Decrement counter
    jnz top         ; If counter not 0, then loop again
done: 
    add ebx, '0'    ; INSTRUCTOR’S QUESTION: Why are we doing this?
    mov [sum], ebx  ; Done, store result in "sum"
display:
    mov edx, 1      ; Message length
    mov ecx, sum    ; Message to write
    mov ebx, 1      ; File descriptor (stdout)
    mov eax, 4      ; System call number (sys_write)
    int 0x80        ; Call Linux kernel
    mov eax, 1      ; System call number (sys_exit)
    int 0x80        ; Call Linux kernel
section .data
    global x
    x: db 2
       db 4
       db 3
    sum: 
       db 0

请帮助我。

0 个答案:

没有答案