Selman ALPDÜNDAR

Taking a character and integer from user in ASM Assembly

Question : Write an assembly program that prompts the user for a character, and then for an integer. The program then prints out “The character entered was: followed by the character, and “The integer entered was: ” followed by the integer.


%include 'asm_io.inc'
segment .data
  msg1 db "Enter a character : ",0
  msg2 db "Enter a integer : ",0
  msg3 db "Entered character was : ",0
  msg4 db "Entered integer was : ",0
 segment .bss
  integer resd 1
  character resb 1
 segment .text
 	global _asm_main
_asm_main:
    enter	0,0
	pusha	
    ;---------------------------- start ponit -----------------------
    mov eax,msg1 ; move msg1 to eax register
    call print_string ; print to screen  msg1
    call read_char ; read a character from user
    mov [character],al; move the al value to character variable

    mov eax,msg2 ; move msg2 to eax register
    call print_string; print to screen msg2
    call read_int ; read a number from user
    mov [integer],al; mov al value to integer variable

    mov eax,msg3; move msg3 to eax register
    call print_string ; print to screen msg3
    mov eax,[character]; move characker  to eax register
    call print_char; print to screen charecter
    call print_nl; move to point new line

    mov eax,msg4; move msg4 to eax register
    call print_string; print to screen msg4
    mov eax,[integer]; move integer to eax register
    call print_int; print to screen number
    ;---------------------------- start end ------------------------------
    popa
	mov	eax, 0
	leave
	ret


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.