Qbasicnews.com
January 20, 2018, 05:31:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Poll
Question: Should I include Qbasic Cameos?  (Voting closed: January 12, 2003, 10:37:44 PM)
Yes - 9 (100%)
Total Voters: 10

Pages: 1 ... 10 11 [12] 13
  Print  
Author Topic: Cobra  (Read 61959 times)
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #165 on: April 29, 2003, 09:39:42 AM »

Sigh.

Quote

Now, don't preach me about Asm portability in linux,


Oh, how come the calling conventions, available interupts and even the syntax differ. Do you recognize the following code, its valid x86 assembley code:
Code:

.data # section declaration

msg:
.ascii "Hello, world!\n" # our dear string
len = . - msg # length of our dear string

.text # section declaration

# we must export the entry point to the ELF linker or
    .global _start # loader. They conventionally recognize _start as their
# entry point. Use ld -e foo to override the default.

_start:

# write our string to stdout

movl $len,%edx # third argument: message length
movl $msg,%ecx # second argument: pointer to message to write
movl $1,%ebx # first argument: file handle (stdout)
movl $4,%eax # system call number (sys_write)
int $0x80 # call kernel

# and exit

movl $0,%ebx # first argument: exit code
movl $1,%eax # system call number (sys_exit)
int $0x80 # call kernel

You will find that if programs using assembler that have been ported to other architectures/operating systems will have different versions of the assembler code for each.

Portability is the art of writting code that can work without modification on any system, the above wont but this will (given a C compiler):
Code:

#include <stdio.h>

int main() {
  printf("Hello World\n");
  return 0;
}

Completely portable, no recoding necessary /ever/.

Quote

And where did I lambast somebody here?

No you didn't, I was talking about Blitz having a short temper with Megaman. Discussion forums are okay for opiniated arguments, but not for absuing people directly.

Quote

He used ASM because Delphi could only go as fast.

Quote

As you may already have known, it's not the language but the logic behind the algo itself.

Very true. It also depends how well you know your language and compiler. For example both of these copy a string source to string dest in C:
Code:

int strcpy(const char *source, char *dest) {
  int i, len;
  len = strlen(source) + 1;
 
  for(i = 0; i < len; i++) {
    dest[i] = source[i];
  }
  return 0;
}  

But the following one is much faster in most implementations:
Code:

int strlen(const char *source, char *dest) {
  while(*source) {
    *dest++ = *source++;
  }
}

Like you said, give an idiot DX and he code a dumb DX game, give a good programmer any language and they will program a damn cool game.

Quote

wait, is this guy saying asm isnt good for coding? bah. trust me, buddy, you want asm code. it's your friend.

Okay, for starters I can code assembler for the following architectures: Mips, sparc (32bit), x86 and the M68HC12. I know when its useful and when its not, and I know its a pain to learn each new architecture, its calling conventions, register sets, etc etc.

Quote

and no matter how good your compiler is, it's not better than the brain at optimizing.

Maybe not, but writting high level C code and then translating to asm would be a much better start than coding asm from scratch. Also, compilers are getting pretty damn smart these days, gcc optomizations flags include such things as: making all functions inline, bulk stack popping, forcing register arithmetic, omitting the frame pointer, loop unrolling, reordering delayed branches, etc etc.

A good read on the pros and cons of using assembley is here:
http://linuxassembly.org/howto/doyouneed.html
Logged

esus saves.... Passes to Moses, shoots, he scores!
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #166 on: April 29, 2003, 11:16:00 PM »

Toonski: A new thread??? I've got a record going here!

Anyhow, as I said before but seemed to get shrouded by other topics, the keyhandler works fine, except that sometimes QB will think I key is being held down that's not. (I tested for the value of certain keys and QB would think they were being held when they weren't) I haven't put any code that forces a key value to go to 1, so can someone give me an idea of what's wrong?

And in other news, Mattress from Mattress Warrior is probably going to be in Cobra. And that's all three QB Characters...
Logged
Hexadecimal Disaster
Been there, done that
*****
Posts: 1123



« Reply #167 on: April 30, 2003, 02:23:10 AM »

BTW, which keyhandler are you using?
Logged

img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #168 on: April 30, 2003, 03:02:41 AM »

The one toonski gave me "a few pages back". With kbd%
Logged
Hexadecimal Disaster
Been there, done that
*****
Posts: 1123



« Reply #169 on: April 30, 2003, 03:36:03 AM »

Hmm... the one that uses INP(96) to read keys.

As far as I remember (AFAIR? Wha...?) you need to clear the keyboard buffer after every check, by using POKE or INKEY$

...that's why I recommended you Milo's code.  :roll:

I'll gonna check it.

-------------------------------------
edited later
-------------------------------------

Yep, it seems that the handler get stuck when using 3 or 4 keys at a time, but the code seems fine. Interestingly enough, the "sticky" keys doesn't always come by using the same sequence, and sometimes the "down-right plus two keys" are read correctly...
Logged

img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #170 on: April 30, 2003, 05:01:43 AM »

Pardon my ignorance but if Linux runs on the x86 architecture, x86 assembly would too. :*).  In fact ASM is not a language at all but a syntactic way to issue instructions on a machine level.

If linux do run on the intel x86 architecture so would any flavor of asm that supports it.

BTW, my code is not TASM or MASM or NASM based, it directly index the stack(manualy) registers so porting it would not be an issue. :*)

TASM is different from NASM or MASM as Basica is Different from QB.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #171 on: April 30, 2003, 06:40:15 AM »

Assembly in Linux for i86s is just the same as it is in DOS/Windows. They only differ in the syntax.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
ak00ma
Ancient Guru
****
Posts: 669



« Reply #172 on: April 30, 2003, 08:45:50 AM »

ASM is important for every codin' language...everytime something is too slow, you might use ASM to tune it up
Logged

B 4 EVER
Blitz
I hold this place together
*****
Posts: 853



WWW
« Reply #173 on: April 30, 2003, 01:38:51 PM »

Are we talkinga bout asm now? neato. Well, i replied to the same thing in the challenge post loose.

Asm is still used allot in the gamedev industry. Becuase there you have lots of innerloops which are time critical. In those situations nothing can replace asm. Not even the best compiler comes near a good asm coder. And it never will, until the day when computers learn to think (and do not twist my words on this one).

However, this does not say that coding something in asm will make it faster then a good compiler. DQB is the perfect example why some people should not use asm and compilers instead.

But compilers ( such as your precious gcc) generate general code. And they can't use such things such as mmx (i'm well aware of vectorC and intel c++), atleast in a good way. For instance, when when coding a sound mixer, you can process up to 24 samples in the same times it takes to process one with normal code.

But ignoring things like that, knowing asm makes you a better high level coder as well. Becuase you know how the computer works and you're able to analyze the code the compiler generates.

That's enough reason to learn it.

And personally, i try to get my code to run as smooth on a p133 as it does on a 3 ghz cpu.
Logged

oship me and i will give you lots of guurrls and beeea
toonski84
__/--\__
*****
Posts: 2567



« Reply #174 on: April 30, 2003, 06:23:22 PM »

so true.  

nate, the one i gave him came from a raycaster antoni gual made, i think.  it uses a poke to clear the buffer each time, and it fixed, at least with me, the problem with the arrow keys locking up.

i'd still recommend milo's though, because only assembly can properly set interrupt vectors and do it properly.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #175 on: April 30, 2003, 08:30:33 PM »

Okay, okay. Im not trying to say that asm is completely useless to learn, just that I would (personally) recommend that people learn high level languages instead. For someone getting into general programming with an interest in making hobbyist games or simple applications, asm is way down the list of programming languages to learn. Moving to the future, things like Java and .NET are pushing programmers even futher away from needing asm. We are probably coming from different angles also, Im mostly into low-level system coding, and you guys are arguing from a game standpoint.

Quote

And they (C compilers) can't use such things such as mmx (i'm well aware of vectorC and intel c++), atleast in a good way

My version of gcc has arch flags for at least the following:  pentium, pentium-pro, pentium-mmx, pentium2, pentium3, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-xp and can compile code that utilises the extended instruction sets provided by each of those architectures. This is difficult for a pure assembley coder because each instruction set is different and multiple asm files would be needed to ensure portability (with a C version you just need a architecture detection script).

Quote

Assembly in Linux for i86s is just the same as it is in DOS/Windows. They only differ in the syntax.

They aren't quite the same when you get into more elaborate asm coding because you have to adhere to the operating systems conventions, such as function call setup, available interupts, alignment rules, etc.

Quote

In fact ASM is not a language at all but a syntactic way to issue instructions on a machine level.

Not quite, most symbolic asm languages contain pseudo-ops and shortcuts. The assembler directives are all pseudo ops, and even some instructions can produce multiple instructions once at machine level. The only example I can think of off hand is one for the sparc where the set operation actually produces a sethi and an or instruction at machine level because a 32-bit word cant fit into a single 32-bit instruction.

Quote

But ignoring things like that, knowing asm makes you a better high level coder as well. Becuase you know how the computer works and you're able to analyze the code the compiler generates.

This is true, but again relates more to someone who is coding at system level, when programming in a highlevel language it is generally a bad thing (IMHO) to be trying to program to the architecture. As I said, most of the asm work I do I work at a high-level language first and then compile to assembler to get a head start. The strcpy code I posted early is an example of knowing what produces better object code in a high-level language.

As for speed of algorithms etc, I disagree completely on using asm. If an algorithm is too slow in a high-level language then it is time to start looking at your data structures and algorithm code to see if you can improve it mathmatically, asm should be a last resort for speed here. (Especially as most modern compilers support optomizations such as loop unrolling and inline functions).

Quote

Asm is still used allot in the gamedev industry. Becuase there you have lots of innerloops which are time critical. In those situations nothing can replace asm.


I havent seen enough comercial game code to be able to comment on this with any amount of certaincy, however I mentioned earlier that the Quake2 source doesnt contain /any/ asm code in the OpenGL version. Not enough game companies are releasing their source code to be able to effectively comment on this. Hobbyist games are not always a good source, because as you said people can code poorly in any language and produce slow code, which may lead them to believe that they need asm code when a little extra work at a high level would do the trick.

So if you are going to learn assembley, then learn when you do and dont need it, how it relates to other languages and what alternatives exist. Dont take what I said to mean that nobody should ever learn asm, I meant that with the vast amount of libraries and advancments in hardware and software speed, asm is becoming less mandatory for general programming. It is still, and always will be highly necessary for niche programming.
Logged

esus saves.... Passes to Moses, shoots, he scores!
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #176 on: May 01, 2003, 02:36:33 AM »

But then again, why are the most widely used of libs in any language made in ASM?

Portability?

Take any Assembler:

mov ax,yval
Xchg Ah,al
Mov di,AX
shr Di,6
Add di,ax
add di,xval

No modifications needed. :*)

"The is a big difference between something that runs on a 486 as opposed to something that *fly's* on a 486"

And why are you assuming the guy who made the DX water demo using delphi should look at his code again. I've seen the code and it's pretty much Delphi-optimized.  But then he needed asm to make it better. :*) And believe me, the *guy* *knows* how to code.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Blitz
I hold this place together
*****
Posts: 853



WWW
« Reply #177 on: May 01, 2003, 05:51:18 AM »

Of course, if you're algo suxs it will suck just as much in asm. The things you're saying are pretty obvious. Look at UGL, a combination of good algos and good asm code. However a compiler could never do that. UGL is as fast at it is becuase good innerloops. A compiler could never even come near those loops.

If asm is so useless why was it used so much before computers had hundreds of megabytes of memory and cpus running at several ghz? These reason was obvious back then, there wasn't even a discussion. They needed to take fulladvantage of every cpu tick. But as cpus got faster and memory larger, they could make large and ineffcient programs. And the reason they do it now is becuase they can.

And gcc isn't even such a good compiler, it's a okay compiler. I highly doubt it uses simd instructions. I'd have to see it to belive it.

And to whoever's using asm code, portability isn't an issue for them. Becuase who actually uses asm? Game developers, for consoles you have to use asm, for pc you're probably coding it for win32. A hobbist, i don't give a horses ass about portability. I don't even like *nix.
Logged

oship me and i will give you lots of guurrls and beeea
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #178 on: May 01, 2003, 07:44:49 PM »

Quote

But then again, why are the most widely used of libs in any language made in ASM?

Standard C library, possibly the most widely used library of them all is coded in C.  Mesa3D OpenGL implementation is written in C, possibly with some asm code for the device drivers (as I mentioned earlier). Wine, which includes an implementation of most of the win32 api is written in C. The Allegro game library is a mixture of C and asm.

Most game libraries only require the drivers to be written in asm (there is no other way here) but the remaining code can be written in a high-level language.

Quote

If asm is so useless why was it used so much before computers had hundreds of megabytes of memory and cpus running at several ghz?


Can you remember where I said:

Quote

IMHO assembler is hardly worth learning these days unless you plan to do low level system or embedded programming.


Note the phrase "these days", of course it was necessary in days of yore. Modern computers on the other hand a blindingly fast and have plenty of memory to burn. Assembler is still very much required for embedded programming where memory and speed constraints are still an issue. Im talking about application development here.

Quote

And gcc isn't even such a good compiler, it's a okay compiler. I highly doubt it uses simd instructions. I'd have to see it to belive it.

It does support simd instructions. In saying that its a not a good compiler, you are taking the one sided approach of speed again. Yes Intel's C can easily produce faster object code, however gcc runs on a vast number of architectures, has a very good support community (last time I had a problem with it, I got a reply from one of the developers within an hour), a well designed extension set, and excellent integration with other tools (automake, xemacs, cvs, indent, etc). Thats why I use it, not because I want highly optomized object code.

Quote

And to whoever's using asm code, portability isn't an issue for them. Becuase who actually uses asm? Game developers, for consoles you have to use asm, for pc you're probably coding it for win32. A hobbist, i don't give a horses ass about portability. I don't even like *nix.

The same game developers who are now releasing their games (often simultaneously) for win32 PC's, the X-Box, PS/2, Dreamcast etc. Are you claiming that any asm code is portable here? For consoles you code in C just like for everything else, most probably cross-compiled from a PC. As a hobbyist you may not care about portability, but for anybody doing serious development these days its a big issue because there is no single target platform for anything now. Applications are faced with the challenge of running on win32 and *nix and games are faced with a vast array of consoles.

Looking to the future the x86 line may soon be dropped being replaced by the IA-64 architecture, which may have backward compatible IA-32 support , but definitely will not run 16 bit x86 code. Also asm goes completely out the window when you shift to Java or .NET unless you really feel compelled to code directly in byte code ;-)
Logged

esus saves.... Passes to Moses, shoots, he scores!
Rokkuman
Na_th_an
*****
Posts: 1973



« Reply #179 on: May 11, 2003, 07:11:09 PM »

Anyways... the only question that comes to my mind is why do the keys get stuck in my game, but they work just fine on that demo... it's the same thing, and it's not like I'm having you hold down 6 keys or anything, the max is 3, and that didn't freeze the demo not once.
Logged
Pages: 1 ... 10 11 [12] 13
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!