From: Frank K. <fbk...@zy...> - 2008-11-09 21:12:20
|
Tyler Littlefield wrote: > Hello, > I'm going to try to write a "guess the number." tyep program. > First, I wrote this, so I could link to it: > #include <cmath> > #include <ctime> > #include <cstdlib> > int rnum(); > int rnum() > { > srand(time(NULL)); I think you want to only do this once. > return (rand()%10); > } > I'm also going to have to write a rapper for itoa. > next, my asm program so far is as follows: > global _start > section .text > welcome db "Welcome to guess the number!",10,"Written by Tyler Littlefield > <ty...@ty...>",10,10 > welcomelen equ $-welcome > texta db "I am thinking of a number between 1 and 10.",10,"Can you guess it > in three tries?",10 > textalen equ $-texta > section .data You've got "section .text" and "section .data" swapped!!! > nop > _start: > nop > mov eax,4 > mov ebx,1 > mov ecx,welcome > mov edx,welcomelen > int 80h > mov eax,4 > mov ebx,1 > mov ecx,texta > mov edx,textalen > int 80h > when I compile with nasm, that works great. but when I gcc ns.o rand.o it > gives errors about _start, "_start" exists in the C "startup" code (crt0.o?), and we only want one - this calls "main", so start your asm code with "main" nd has to be declared global), not "_start". Or link with "ld -o myprog ns.o rand.o -I/lib/ld-linux.so2 -lc". > and then says it can't find time and srand and > rand. > Ideas? Dunno about that one. I thought those were "standard"... shouldn't need underscores... Dunno. Jeff Duntemann's got a "rand()" example in linuxcode.zip from: http://www.copperwood.com/pub/ I'm "working on" (figure of speech) a reply from a couple messages ago with a few simple C/asm examples... I'll get back to ya "real soon now"... (incidentally, to reply to this list, hit "reply all" - just "reply" replies only to the sender - I'm not sure the message I refer to actually made it to the list...) I'll get back to ya - and see my post on the forum... might help... Best, Frank |