LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2013, 06:14 PM   #16
errigour
Member
 
Registered: May 2009
Posts: 366

Original Poster
Rep: Reputation: 6

Im starting to think I might have to define the digits 0-9
 
Old 01-08-2013, 07:39 PM   #17
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, from Introduction to UNIX assembly programming, it looks like you need the following to be true:
  • EDX = length of message, in bytes
  • ECX = pointer to message
  • EBX = file descriptor; stdout = 1
  • EAX = 4, sys-write system call
The data at the place pointed to by ECX better be ASCII data, or it isn't going to be pretty.
The example at the link above:
Code:
	mov	edx,len	;message length
	mov	ecx,msg	;message to write
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel

	mov	eax,1	;system call number (sys_exit)
	int	0x80	;call kernel

section	.data

msg	db	'Hello, world!',0xa	;our dear string
len	equ	$ - msg			;length of our dear string
The label 'msg' is the start of a string of ASCII characters, followed by a linefeed. These are printable, being understood by the assembler as such because of their enclosure in quotes. The terminating '0xa', not enclosed in quotes is a defined byte with the explicit value '0x0a', ten in decimal, or possibly in ASCII as '\n'.

Add another section of defined bytes:
Code:
bindata   db    0,1,2,3,4,5,6,7,8,9
asciidata db    '0123456789'
Assemble the code with an option to see the assembler listing showing the opcodes, immediate data, and static data. Compare the two sections of binary data and ASCII data starting at the 'bindata' label. See the difference? The 'asciidata' section will be printable.

If you want to print static data, make the static bytes printable characters by enclosing it in quotes. If you have an arbitrary binary value that you want displayed in its ASCII string representation, you will have to convert it to ASCII in memory. This can be a bit tricky if you need to see it in its decimal notation, but relatively simple if you want to display it as hexadecimal.


--- rod.

Last edited by theNbomr; 01-08-2013 at 07:44 PM.
 
Old 01-08-2013, 07:54 PM   #18
errigour
Member
 
Registered: May 2009
Posts: 366

Original Poster
Rep: Reputation: 6
alright thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nasm assembler; output numbers? infinity42 Programming 4 05-26-2018 01:22 PM
assigning color to numbers and plotting in GNUPLOT pravas Linux - Newbie 1 12-08-2011 12:05 PM
Assigning large numbers of IPv6 addresses jack_sprat Linux - Networking 0 10-02-2007 10:04 AM
Assigning IP numbers on home network moonmoth Linux - Newbie 3 11-18-2004 11:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration