NASM Linux Assembly Printing Integers

前端 未结 3 1184
失恋的感觉
失恋的感觉 2021-02-04 18:41

I am trying to print a single digit integer in nasm assembly on linux. What I currently have compiles fine, but nothing is being written to the screen. Can anyone explain to me

3条回答
  •  心在旅途
    2021-02-04 19:07

    After reviewing the other two answers this is what I finally came up with.

    sys_exit        equ     1
    sys_write       equ     4
    stdout          equ     1
    
    section .bss
        outputBuffer    resb    4       
    
    section .text
        global _start
    
    _start:
        mov  ecx, 1                 ; Number 1
        add  ecx, 0x30              ; Add 30 hex for ascii
        mov  [outputBuffer], ecx    ; Save number in buffer
        mov  ecx, outputBuffer      ; Store address of outputBuffer in ecx
    
        mov  eax, sys_write         ; sys_write
        mov  ebx, stdout            ; to STDOUT
        mov  edx, 1                 ; length = one byte
        int  0x80                   ; Call the kernel
    
        mov eax, sys_exit           ; system exit
        mov ebx, 0                  ; exit 0
        int 0x80                    ; call the kernel again
    

提交回复
热议问题