flat assembler
Message board for the users of flat assembler.

Index > DOS > I'm new and I have a question.

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2 26 Sep 2006, 07:33
I recently started assembly and I made this thing.

Code:
macro cout char{mov ah,2
mov dl,char
int 33}
org 256
a db 20 dup 0
mov [a],byte 1
mov cx,0
loopa:;main loop
inc cx
mov bx,0
shift:
shl byte[a+bx],1
inc bx
cmp bx,20
jl shift
mov bx,0
loopb:
cmp [a+bx],byte 10
jl weird
sub byte[a+bx],10
inc byte[a+bx+1]
weird:
inc bx
cmp bx,20
jl loopb
mov bx,20-1
loopc:
mov dl,[a+bx]
add dl,48
cout dl
dec bx
cmp bx,0
jge loopc
cout 10
cmp cx,64
jl loopa
int 32
    



It prints the first 64 powers of 2 when I assemble as a .com file.
but the problem is when I do

Code:
macro cout char{mov ah,2
mov dl,char
int 33}
org 256
a db 20 dup 0
newthing db 0 ;declare newthing variable
mov [a],byte 1
mov cx,0
loopa:;main loop
inc cx
mov bx,0
shift:
shl byte[a+bx],1
inc bx
cmp bx,20
jl shift
mov bx,0
loopb:
cmp [a+bx],byte 10
jl weird
sub byte[a+bx],10
inc byte[a+bx+1]
weird:
inc bx
cmp bx,20
jl loopb
mov bx,20-1
loopc:
mov dl,[a+bx]
add dl,48
cout dl
dec bx
cmp bx,0
jge loopc
cout 10
cmp cx,64
jl loopa
int 32
    


it only prints twenty 0s and stops.
I don't know why adding a new variable that isn't even used would cause a problem!

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.


Last edited by 2 on 26 Sep 2006, 20:30; edited 1 time in total
Post 26 Sep 2006, 07:33
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 26 Sep 2006, 08:30
Put the data after the code.
Post 26 Sep 2006, 08:30
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Sep 2006, 08:55
and use "[code]" blocks when posting code here
Post 26 Sep 2006, 08:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 26 Sep 2006, 21:21
Thanks a lot! I feel like such an idiot! I am supposed to put the data after the code! My new program does the first 256 powers of 2 and
doesn't have trailing 0s.

Code:
macro cout char{mov ah,2
mov dl,char
int 33}
org 256
mov [a],byte 1
mov cx,0
main:
inc cx
mov bx,0
shift:
shl byte[a+bx],1
inc bx
cmp bx,[d]
jle shift
mov bx,[d]
cmp byte[a+bx],10
jl dig
inc [d]
dig:
mov bx,0
carry:
cmp [a+bx],byte 10
jl weird
sub byte[a+bx],10
inc byte[a+bx+1]
weird:
inc bx
cmp bx,[d]
jle carry
mov bx,[d]
;dec bx
loopc:
mov dl,[a+bx]
add dl,48
cout dl
dec bx
cmp bx,0
jge loopc
cout 10
cmp cx,256
jl main
int 32
a db 80 dup 0
d dw 0
    
Post 26 Sep 2006, 21:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Sep 2006, 23:32
next step: write your macros in readable manner:

Code:
macro cout char
{
    mov ah, 2 
    mov dl, char 
    int 33
}    


next step: write your CODE in readable manner. This is most widespread standard of formatting asm code:
Code:
        mov     [a],byte 1 
        mov     cx,0 
main: 
        inc     cx 
        mov     bx,0 
shift:
        shl     byte[a+bx],1 
        inc     bx 
        cmp     bx,[d] 
        jle     shift 
        mov     bx,[d]
...etc...
    
Post 26 Sep 2006, 23:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 27 Sep 2006, 02:37
vid,I am a freak about small size. It's why I don't include those extra
spaces or new lines when I don't have to. If a file is 2 bytes smaller and
yet hard to read,I still find it worth the tradeoff. For the most part,my
code is for my personal use and it's not really meant to be read.
I thought that good coders can read it. If the compiler reads it then I
consider it acceptable. Many times I've had to take the time to
read other people's code.
Post 27 Sep 2006, 02:37
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista 27 Sep 2006, 03:10
@2 - spaces and formating don't add to the size of your executable. readability is not just for freshly coded routines, but for six months from now. without good coding style and practices, you won't be able to make heads nor tails from your code six months from now. in fact, i'd get into the habit of adding comments to your code as well if i were you. i don't think you'd be happy with what "good coders" think when they read your source as written.

vid is taking the time out of his busy schedule to show you good style for a reason. i wouldn't discount it out-of-hand as too much trouble, or assume your skills are beyond it. others less skilled than you can benefit from well styled and commented code from you. and you will benefit too.

don't worry, i received the "wrath of vid" a while back on my code style... he said it was "hackish" and "spaghetti code". he was right. his advice helped me very much.

you've found the best assembler and asm community there is, make your code style created with it and within it worthy Cool
Post 27 Sep 2006, 03:10
View user's profile Send private message Visit poster's website Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 27 Sep 2006, 04:42
Yes,I shall. Just so you know,I was also trying 2 keep my source size
small,but then,if I was after small source,I wouldn't even be doing ASM
now would I? LOL

BTW@vid,thanks 4 your advice,I'm just a little paranoid from past bad
forum experiences.
Post 27 Sep 2006, 04:42
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 27 Sep 2006, 04:46
2, that's true, ASM is not for small source size. Heck, check out the IOCCC, it's got a chess program in 64 lines of C. Laughing
Post 27 Sep 2006, 04:46
View user's profile Send private message Visit poster's website Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista 27 Sep 2006, 10:30
Quote:
I'm just a little paranoid from past bad
forum experiences.


@2 - you don't need to worry about that here. you have a good attitude, eager to learn, and a great sense of wanting to exeriment and learn. you'll fit in well here.
Post 27 Sep 2006, 10:30
View user's profile Send private message Visit poster's website Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 29 Sep 2006, 02:46
Quote:

@2 - you don't need to worry about that here. you have a good attitude, eager to learn, and a great sense of wanting to exeriment and learn. you'll fit in well here.


Thanks alot. You know,I'm kind of help back in my assembly.
I kinda wish I had a small standard library that could do console
input and output like you can with printf and scanf in C.
Is there a good standard library for DOS?
Post 29 Sep 2006, 02:46
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Sep 2006, 04:45
not really "standard", but there are some on programmers heaven. however i don't know if/how they can be used with FASM
Post 29 Sep 2006, 04:45
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 29 Sep 2006, 04:56
Right,there is nothing standard about it. I have used the FASM version
of HLA,but it was a Windows thing. I like my com files cause they are DOS
compatible. I may seem silly how I like DOS,but I have some very interesting reasons behind it.
Post 29 Sep 2006, 04:56
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 01 Oct 2006, 19:35
@2 (the "@"s seem to be the trend nowadays in this thread Wink ) - That's not silly at all, that you want things to be DOS compatible! If you look in the OS Developers section of the forum, you'll notice that a lot of the OS's are actually meant to run over DOS (DOS based, per se).
Post 01 Oct 2006, 19:35
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 01 Oct 2006, 19:45
Quote:

@2 (the "@"s seem to be the trend nowadays in this thread ) - That's not silly at all, that you want things to be DOS compatible! If you look in the OS Developers section of the forum, you'll notice that a lot of the OS's are actually meant to run over DOS (DOS based, per se).


Thanks. Although I run WinXP,I like things about DOS EXEs.
First of all,they run in DOS. LOL. I test them with DOSBOX.
Second,those Windows compilers do strange things and have such a
dependency on DLLs. That is something I don't like.
That why I program things in DJGPP.

Here is something good I made. http://darkchandler.50webs.com/bitfun.zip
Post 01 Oct 2006, 19:45
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 03 Oct 2006, 00:18
Ah, and I totally understand your point of view about it. One of my favorite things about DOS executables is their simple file format (IIRC, all you need for the .COM filetype is the address in memory where the executable loads, though the odd thing is that I've made .COM files where they load up without that, so it's like a flat binary.)
Post 03 Oct 2006, 00:18
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 03 Oct 2006, 08:24
erm, and the bitfun executable thinks that all the World is about US-keyboard. We have like 194 countries and at least as many different variations of keyboards. ++ there are also laptops. Don't you think it would be better to make it key-based not code-based?

The second thing that disturbs and doesn't make it any funnier is that the 1-0 are the last bits. They should be the first as the highest order bits or if it is REALLY necessary then at least reverse them.

Hmm, actually another problem - in 32-bit world 1-8, Q-I, A-K, Z-('<'; ','; the key after M) would be more logical - one row of keys for every byte.

The most trivial problem is porting to ASM I think - I might do it myself after the lunchbrake if others haven't beaten me to it. Very Happy

PS. 53KB program is maybe too much for a size-freak Wink
Post 03 Oct 2006, 08:24
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 04 Oct 2006, 04:21
First of all, I'm no C programmer, BUT:

  • combine the printf()s into one
  • #define B break (or similar, to reduce ugly code repetition)
  • I'm sure you could #define a macro too that would make all the ^=1 disappear (or look better, at least)
  • at least UPX your .EXE (DJGPP is overkill for this program) Smile


P.S. DOS 4ever!
Post 04 Oct 2006, 04:21
View user's profile Send private message Visit poster's website Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 05 Oct 2006, 07:22
Quote:

First of all, I'm no C programmer, BUT:



combine the printf()s into one

#define B break (or similar, to reduce ugly code repetition)

I'm sure you could #define a macro too that would make all the ^=1 disappear (or look better, at least)

at least UPX your .EXE (DJGPP is overkill for this program)


I don't know HOW 2 combine the printfs.
I only can do C based on the few things I've read.
BTW,I updated that program recently,it should be at the same link.
Post 05 Oct 2006, 07:22
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 07 Oct 2006, 22:57
Okay, well, I'm no C coder (like I said), but here's my (GNU unified) diff of your Oct. 4th version, so use these fixes if you want:

P.S. gcc -s -Wall -Wextra bitfun.c -o bitfun.exe is now silent (tested w/ GCC/DJGPP 4.1.0). Smile


  • added include<pc.h> for ScreenSetCursor
  • readded clrscr() call (seems to be needed, otherwise can't see info)
  • merged some printf()s (to save space)
  • fixed second printf() format to handle long numbers
  • int main() is used now plus return 0;


Code:
--- bitfun.c    2006-10-04 17:07:08 +0000
+++ bitfun-tweak.c      2006-10-07 17:47:44 +0000
@@ -1,21 +1,32 @@
 #include<stdio.h>
 #include<string.h>
 #include<conio.h>
+#include<pc.h>
 long int a,b,d,x;
 char c,s[32];
-main()
+int main()
 {
+clrscr();
 _setcursortype(_NOCURSOR);
 ScreenSetCursor(0,36);printf("bin");
 ScreenSetCursor(1,36);printf("hex");
 ScreenSetCursor(2,36);printf("dec unsigned");
 ScreenSetCursor(3,36);printf("dec signed");
 ScreenSetCursor(5,0);
-printf("This is my long int toy!\nIt lets you mess with each bit!\n");
-printf("All 32 of the bits are assigned to a keyboard key. Here they are.\n");
-printf("12345678qwertyuiasdfghjkzxcvbnm,");
-printf("\nThere are also 3 special controls!\n");
-printf("0 resets all bits to 0,9 inverts them,and / exits.\n");
+
+//printf("This is my long int toy!\nIt lets you mess with each bit!\n");
+//printf("All 32 of the bits are assigned to a keyboard key. Here they are.\n");
+//printf("12345678qwertyuiasdfghjkzxcvbnm,");
+//printf("\nThere are also 3 special controls!\n");
+//printf("0 resets all bits to 0,9 inverts them,and / exits.\n");
+
+printf("This is my long int toy!\nIt lets you mess with each bit!\n\
+All 32 of the bits are assigned to a keyboard key. Here they are.\n\
+12345678qwertyuiasdfghjkzxcvbnm\
+\nThere are also 3 special controls!\n\
+0 resets all bits to 0,9 inverts them,and / exits.\n");
+
+
 x=1;
 while(x){
 ScreenSetCursor(0,0);
@@ -23,9 +34,14 @@
 for(b=31;b>=0;b--){s[b]=d&1;s[b]+=48;d>>=1;}
 printf("%s",s);printf("\n");
 ScreenSetCursor(1,24);
-printf("%08X\n",a);
-printf("%32u\n",a);
-printf("%32d\n",a);
+
+//printf("%08X\n",a);
+//printf("%32u\n",a);
+//printf("%32d\n",a);
+
+printf("%08lX\n%32lu\n%32ld\n",a,a,a);
+
+
 c=getch();
 switch(c){
 case ',':a^=1;break;
@@ -65,4 +81,5 @@
 case '/':x=0;break;
 }
 }
+return 0;
 }
    
Post 07 Oct 2006, 22:57
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.