Jump to content

hi i want to write a simple character printing program plz help !

- - - - -

  • Please log in to reply
1 reply to this topic

#1
rohithk

rohithk

    Newbie

  • Members
  • Pip
  • 1 posts
hi ! i am new on this foroum and this is my vary first post ! I am a newbie is asm too !
i tried a code to accept a character and print the same !
i can accept it with following code but its not working with printing that character
i am a linux nasm user
segment .data

msg1: db 'Enter a key',10

msg1len: equ $-msg1


msg2: db 'the key entred is',10

msg2len: equ $-msg2




segment .text

global _start


_start:


mov eax,4

mov ebx,1

mov ecx,msg1

mov edx,msg1len

int 80h


call getchar

call putchar


mov eax,1

mov ebx,0

int 80h


getchar:


pushad 


pushfd 


mov eax, 3 


mov ebx, 0 


mov ecx, esi 


mov edx, 2 


int 80h 


popfd 


popad 


ret 


putchar:


pushad


pushfd


mov eax,4

mov ebx,1

mov ecx,esi

mov edx,2

int 80h


popfd


popad


ret
thanks in advance :)

#2
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
I hope my code helps:


segment .data

	MSG1: db "Please enter a character...", 0xa, 0xd ;<--- carriage return + new line

	LEN1: equ $-MSG1

	MSG2: db "You entered: "

	LEN2: equ $-MSG2

	

	;New line string

	NEWL: db 0xa, 0xd

	LEN3: equ $-NEWL


segment .bss

	INPT: resb 1


segment .text

	global _start

_start:

	;Print first message

	mov eax, 0x4

	mov ebx, 0x1

	mov ecx, MSG1

	mov edx, LEN1

	int 0x80


	;Print second message (no new line)

	mov eax, 0x4

	mov ebx, 0x1

	mov ecx, MSG2

	mov edx, LEN2

	int 0x80


	;Read character

	mov eax, 0x3

	mov ebx, 0x1

	mov ecx, INPT

	mov edx, 0x1

	int 80h


	;Print new line

	mov eax, 0x4

	mov ebx, 0x1

	mov ecx, NEWL

	mov edx, LEN3

	int 0x80


	;Terminate

	mov eax, 0x1

	xor ebx, ebx

	int 0x80


To create the application, do this (terminal):


cd /Path/To/Source/Location/

nasm -f elf NAME.ASM

ld NAME.o


Greets,
artificial

Edited by artificial, 27 July 2010 - 05:34 AM.
Comment

Sometimes words ain't enough to express something. That's why computer scientists use double words.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users