LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-22-2012, 09:18 AM   #1
errigour
Member
 
Registered: May 2009
Posts: 302

Rep: Reputation: 6
Linux Assembly: write and receive assembly data


How do I initialize lenin and strin for the code below?

Code:
code removed. It did not function.

Last edited by errigour; 09-22-2012 at 10:56 AM.
 
Old 09-22-2012, 09:21 AM   #2
errigour
Member
 
Registered: May 2009
Posts: 302

Original Poster
Rep: Reputation: 6
woops meant to make a different question edit ignore this post sorry.
 
Old 09-22-2012, 10:54 AM   #3
errigour
Member
 
Registered: May 2009
Posts: 302

Original Poster
Rep: Reputation: 6
Iv'e solved this problem, here's the code. It receives 64 characters, any more and it sends the output to the linux command interpreter.

Here's where I learned how and its awesome coffee: Section 3.2.1 and 3.2.1,
http://www.nasm.us/doc/nasmdoc3.html

recv and write data with int80h
http://faculty.stedwards.edu/laurab/...31/int80h.html


compile the below as follows,
nasm -f elf -o input.o input.asm
ld -s -o input input.o
./input
Type 65 characters if you want to. just try not to type anything you wouldn't want linux to do if it is carried over the 64 character limit.
Code:
;db 8 bit
;dw 16 bit
;dd 32 bit
;dd 64 bit

SECTION .data ; Initialized data
;SECTION .data decleration examples
;      db    0x55                ; just the byte 0x55 
;      db    0x55,0x56,0x57      ; three bytes in succession 
;      db    'a',0x55            ; character constants are OK 
;      db    'hello',13,10,'$'   ; so are string constants 
;      dw    0x1234              ; 0x34 0x12 
;      dw    'a'                 ; 0x61 0x00 (it's just a number) 
;      dw    'ab'                ; 0x61 0x62 (character constant) 
;      dw    'abc'               ; 0x61 0x62 0x63 0x00 (string) 
;      dd    0x12345678          ; 0x78 0x56 0x34 0x12 
;      dd    1.234567e20         ; floating-point constant 
;      dq    0x123456789abcdef0  ; eight byte constant 
;      dq    1.234567e20         ; double-precision float 
;      dt    1.234567e20         ; extended-precision float
; msg: db "Hello world, this is assembly",10,0
msg	db	'# ',0			;our dear string
len	equ	$ - msg			;length of our dear string

SECTION .bss  ; Uninitialized data
;SECTION .bss decleration examples
;buffer:         resb    64              ; reserve 64 bytes 
;wordvar:        resw    1               ; reserve a word 
;realarray       resq    10              ; array of ten reals 
;ymmval:         resy    1               ; one YMM register
strin:	resb	64
lenin	equ	64

SECTION	.text ; Assembly code
    global _start			;must be declared for linker (ld)

_syscall: ;Function called with call _syscall
	int	0x80	;system call
	ret
    
_start:			;tell linker entry point

_input:
	;print comman line prompt
	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	80h

	;receive input
	mov	edx,lenin	;message length
	mov	ecx,strin	;message to read
	mov	ebx,2		;file descriptor (stdin)
	mov	eax,3		;system call number (sys_read)
	int	80h
	
_exit:	
	mov	eax,1		;system call number (sys_exit)
	int	0x80
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Centos 5 install error (Do you want to initialize hdg and lose all data) v00d00101 Linux - Enterprise 2 03-09-2008 10:26 PM
How to initialize const data members in base classin cpp? milky.way Programming 1 11-24-2007 11:30 PM
multipling 64bit data type in assembly irfanhab Programming 3 12-06-2004 05:41 PM
Possible to read/evaluate a-z chars in assembly? laksi Programming 3 08-08-2004 08:54 PM
Only Read if you know some Assembly AquamaN Programming 10 12-11-2003 05:16 PM

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

All times are GMT -5. The time now is 03:10 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration