NASM Assembly How to convert input to int

  Kiến thức lập trình

I am making a program to take input of an int and print the ASCII char based on the int but I don’t know how to convert the input.

Ex. Input is 65, program should print.

SECTION .data
msg1 db ‘Please enter a number: ‘, 0 ; message string asking user for input

SECTION .bss
sinput: resb 3 ; reserve a 255 byte space in memory for the users input string

SECTION .text
global _start

_start:

mov     eax, msg1
call    sprint

mov     edx, 2        ; number of bytes to read
mov     ecx, sinput     ; reserved space to store our input (known as a buffer)
mov     ebx, 0          ; read from the STDIN file
mov     eax, 3          ; invoke SYS_READ (kernel opcode 3)
int     80h

;

mov     eax, sinput     ; move our buffer into eax (Note: input contains a linefeed)
call    sprintLF          ; call our print function

//Above is reading and printing the input
//Below is a test that prints A, but i want to assign the input instead of 65

mov     ecx, 65          ; ecx is initalised to zero.

mov     eax, ecx        ; move the address of our integer into eax
push    eax             ; push eax to the stack
mov     eax, esp        ; get the address of the character on the stack
call    sprintLF        ; call our print function

pop     eax             ; clean up the stack so we don't have ng
call    quit

I’ve tried some other functions from similar problems but nothing works.

New contributor

DHigo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT