Skip to main content
GameDev.net gamedev.net
🔒 Locked

ASM Question

Started by Esap1 Sep 4, 2000 at 4:54 PM 10 replies 600+ views
Original Post
Esap1
Esap1
Im playing with assembly(using TASM), and trying to make a loop, in a loop, using ah,al. In C it would look sumtin like for(first=0; first<256; first++) { for(second=0; second<256; second++) { /*Somecrap*/ } } In Assembly I have this, but it crashes: .MODEL SMALL .STACK .CODE mov ah,0 mov al,0 mov bh,0 mov bl,0 START1: add ah,1 mov al,0 START2: add al,1 cmp al,255 jnz START2 cmp ah,255 jnz START1 END What am I doing wrong?
Topgoro
Topgoro
Hi.

The problem with the ASM version is that both loops are exiting when their respective values reach 255 (cmp ah/al, 255) instead of 256 as in the C loops (First/Second < 256).

Just compare both ah and al against 0 (zero) instead of 255.

Also, make sure that in the piece of code that you refer to as "some crap" is not changing the value of AX.

Also, at the end of you code you need to put a "ret" instruction is you are executing this code in DOS (in DOS ret returns to a "int something" (forgot which interrupt) instruction to quit to DOS) or in the case of Windows, a call to "ExitProcess", otherwise the processor will just continue executing whatever garbage follows your code.

Topgoro
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.
GoofProg
GoofProg
I cannot remember the subfunction.. but it is in int 0x24.. man.. my DOS knowledge is rotting away =(
The nightmare travels across the cosmos with his burning mane.  The trail of ash that is produced. ?Have a nice day!?
Esap1
Esap1
Ill look through some example and try to find how to return to DOS, though do I need this if Im in WIN NT(2000). I bet I do dont I?
MatsG
MatsG
it´s:

mov ax,0x4c00
int 0x21
Esap1
Esap1
I found it just found it then read your post, thanks for the help though.

I had another question. I made a loop(actually a loop in a loop in a loop.....5 times). It loops 5 billion times. Its in Assembly. It takes about 25 seconds to complete. Now is this slow, I thought it would be faster if Im not accessing memory only accessing Registers.
Esap1
Esap1
Actually the inner loop contains nothing, and Im running on an Athlon500@700, but its probally slower because Im in Windows 2000 in a command window, and it probally has to interpret the stuff right?
Topgoro
Topgoro
Hi all.

quote:
Original post by Esap1

Actually the inner loop contains nothing, and Im running on an Athlon500@700, but its probally slower because Im in Windows 2000 in a command window, and it probally has to interpret the stuff right?


I am afraid to tell you no, wrong. Command window applications execute as any regular Windows application. If I am right, when you write to directly to the video memory, it generates a page fault which allows windows to update the application's window.

Let's try to write a simple piece of code to loop 5 billion times:

mov ecx,2 ;two 2.5billion loops
Loop1:
mov edx,2500000000
Loop2:
dec edx
jnz Loop2
dec ecx
jnz Loop2

Let's see:

dec edx, 1 cycle, jnz 3, = 10000000000, * 2 = 20000000000 cycles(the external loop clycle count is not too significant in this case)

This would take 44 seconds in my 450MHz processor, and about 29 seconds in yours. Well, it should take a bit more because Windows always takes some of the processor time away.

So pal, you are already going as fast as it gets in that machine.

Topgoro


Edited by - Topgoro on September 5, 2000 7:48:29 AM
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.
baskuenen
baskuenen
    
.MODEL SMALL
.STACK
.CODE

main:
xor ax,ax
loopit:
inc al
jnz loopit

; do your stuff

inc ah
jnz loopit

; exit to dos
mov ax,0x4c00
int 0x21

END main


I''m getting a little rusty with this, so please correct me if I''m wrong...

Esap1
Esap1
Topgoro: You dont have to be sorry that Im wrong, it happens uncommon,
PS: Is it different in NT though(I mean running Dos Programs, cause it seems slower).
Topgoro
Topgoro
quote:
Original post by Esap1

Topgoro: You dont have to be sorry that Im wrong, it happens uncommon,
PS: Is it different in NT though(I mean running Dos Programs, cause it seems slower).


Hi all.

Well, I played Mortal Kombat in both MAME versions: DOS and Windos. The DOS version had a slightly better frame rate.

But it was on Windows 95 or 98 I don''t remember. In NT it is another story because it won''t allow aplication access the harware directly. Everything is virtualized. For instance, if a DOS program writes to the IO ports to manipulate the sound card, an exeption is generated and depending on the IO registers accessed the NT drivers emulate the sound card functionality. Please, correct me if wrong, thanks.

Topgoro
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.