Jump to content

Assembler newb

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Rakshasas84

Rakshasas84

    Newbie

  • Members
  • Pip
  • 2 posts
Hello everyone,

I am trying to learn assembler. I am writing a very simple program that will XOR a 7 digit string with the key 236, but I am first trying to get my feet wet with something simple.

I am trying to first display the prompt: Number (7 digits):, which I am able to do, BUT then I want to accept user input (no clue how) and display the input.


section	.text


    global _start			;must be declared for linker (ld)




_start:					;tell linker entry point




	mov	edx,promptNumLen	;prompt length


	mov	ecx,promptNum	;prompt text


	mov	ebx,1	;file descriptor (stdout)


	mov	eax,4	;system call number (sys_write)


	int	0x80	;call kernel


	mov 	eax, 5

	mov	[cipherText], eax


	mov	edx,1	; Number length


	mov	ecx,cipherText	; Number 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




promptNum		db	'Number (7 digits): ',0xa	


promptNumLen		equ	$ - promptNum		





section .bss

	cipherText resd 1


Since I dont know how to accept user input yet, I wanted to hardcode 5 to cipherText and just display that.

All it does is display
-------------------------
Number (7 digits):

The expected output is
------------------------------
All it does is display:
Number (7 digits):
5

Any tips? (And yes this is homework, but the homework portion is to encrypt the number and then decrypt, which I have already done in C. I just need to convert to assembler)

Thanks,

Rakshasas84

#2
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
Which OS do you use? You can use use int 21h for Windows (actually for DOS) and int 80h for Linux. Another solution is to interface assembly and C, so you can use functions like printf() etc.

EDIT: Okay, sorry. You already use int 80h.

Greets,
artificial

Edited by artificial, 01 August 2010 - 02:51 PM.
EDIT

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

#3
Rakshasas84

Rakshasas84

    Newbie

  • Members
  • Pip
  • 2 posts
I've been reading up on using C functions, but I really need to use pure assembler for this. I am having trouble finding documentation that shows anything more complex than helloworld. And yes, this is off linux.

Thanks

#4
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
I hope these links help:
Link 1
Link 2

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

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
You do realize that your system call to write() isn't a printf(); whatever binary data is in there will get dumped into stdout. You need to convert the number into a string first, and then use the interrupt.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users