Jump to content
  • Advertisement
Neo C

Generate number in range and compare it to user input

Recommended Posts

Posted (edited)

Hey everyone, i'm new in assembly 32 bits. I would like to know how can i generate a random number in range 0 - 255 in assembly 32 bits (Linux). I already implemented a code :

segment .data
 
msg:		db "Enter number between 255 et 0 :"
len:		equ $-msg
nom_fic:	db "/dev/urandom", 0	
	
segment .bss
choice:	resb 17			;
len_choice:	resb 1
buffer:	dd 0

segment .text
	global _start		; 
_start:

	mov eax, 5		; open file
	mov ebx, nom_fic	;file name
	mov ecx, 0		; options
	int 0x80		; 
        push eax 		;

	mov eax, 3
	pop eax			; 
	mov ebx, eax		;
	mov ecx, buffer
	mov ebx,1
	int 0x80


	
		

	mov eax, 4
	mov ebx, 0
	mov ecx, msg
	mov edx, len
	int 0x80

	mov eax, 4
	mov ebx, 0
	mov ecx, buffer
	mov edx, 1
	int 0x80

	mov eax, 6		
	int 0x80

	mov ebx, 0		; 
	mov eax, 1		;  
	int 0x80		; 

As i said, i'm only a beginner, i can't translate what i want into a code, so please implement a code. Thank you so much !

Edited by Neo C

Share this post


Link to post
Share on other sites
Advertisement

Is this home work?

Any way, find a pseudo random number generator algorithm and implement it. The simplest are quite simple in assembly language.

Share this post


Link to post
Share on other sites

I mean that i can't translate what i want to do into a code.

Yes  this a homework

I found a function that return generate the number, thanks for u help

Share this post


Link to post
Share on other sites
5 hours ago, Neo C said:

Yes  this a homework

We don't help with homework here. Talk to your professor and your fellow students.

Locking thread.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!