Created
November 26, 2023 07:57
-
-
Save pacifiquem/a79bf619b9fad07bbb6eb8279f39af1e to your computer and use it in GitHub Desktop.
Get input from user (his/her) name and then print it to the screen by using ``assembly``!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
msg db 'Enter your name: ', 0 | |
msg_len equ $ - msg | |
buffer resb 64 ; Buffer to store the user's input | |
output_msg db 'Hello, ', 0 | |
section .text | |
global _start | |
_start: | |
; Display prompt | |
mov eax, 4 ; syscall: write | |
mov ebx, 1 ; file descriptor: STDOUT | |
mov ecx, msg ; message to write | |
mov edx, msg_len ; message length | |
int 0x80 ; call kernel | |
; Read user input | |
mov eax, 3 ; syscall: read | |
mov ebx, 0 ; file descriptor: STDIN | |
mov ecx, buffer ; buffer to store input | |
mov edx, 64 ; maximum number of bytes to read | |
int 0x80 ; call kernel | |
; Display output message | |
mov eax, 4 ; syscall: write | |
mov ebx, 1 ; file descriptor: STDOUT | |
mov ecx, output_msg ; output message | |
mov edx, 7 ; message length | |
int 0x80 ; call kernel | |
; Display user input | |
mov eax, 4 ; syscall: write | |
mov ebx, 1 ; file descriptor: STDOUT | |
mov ecx, buffer ; user input | |
int 0x80 ; call kernel | |
; Exit program | |
mov eax, 1 ; syscall: exit | |
xor ebx, ebx ; exit code 0 | |
int 0x80 ; call kernel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment