flat assembler
Message board for the users of flat assembler.

Index > DOS > Read string - newbie Q

Author
Thread Post new topic Reply to topic
C++arl



Joined: 12 Apr 2007
Posts: 2
C++arl 12 Apr 2007, 14:13
Hi all, i'm new to assembler, so bare with me on this one. I have done quite a bit of C, C++ and java so i'm not a total programming beginner. Anywho, i'm currently working on a simple calculator and get some strange results and i belive this might have to do with how i read input. I want to read a string from the keyboard, and use dos interupt 21, AH = 01, which only reads a character, so i try to store each char in a array and then advance the pointer to the array and read in the next char and so on. Have a look at my code:
Code:
mov ah, 01h
mov bx, num2 ; bx = pointer to num2
@@:
       int 21h
       cmp al, 13 ; 13 = enter
       je @f
       mov byte [bx], al
       inc bx
       jmp @B

@@:
       ret    

num2 is declared like this:
Code:
num2 DW 16 dup 24h    


Am i doing anything wrong when reading input, or is the problem elsewhere in the rest of my code?

The complete sourcefile is attatched, if someone is intrested.

Any help will be greatly appreciated ~ C++arl


Description: Little update, not much...
Download
Filename: Calc.ASM
Filesize: 3.4 KB
Downloaded: 471 Time(s)


_________________
Apprentice...


Last edited by C++arl on 13 Apr 2007, 08:58; edited 2 times in total
Post 12 Apr 2007, 14:13
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 12 Apr 2007, 15:50
format MZ ;exe format
org 0x100 ;standard startpunkt (256)

I don't know about the org 100h directive... the entry point for ms-dos exe format is relocatable.

I ran your code and it works good but I think org 100h introduce may introduce sublte bugs?

I hope someone can elaberate some more...
Post 12 Apr 2007, 15:50
View user's profile Send private message Reply with quote
C++arl



Joined: 12 Apr 2007
Posts: 2
C++arl 12 Apr 2007, 16:45
As far as i know 'format MZ' makes it assemble to a exe file instead of just a bin file, which is what i get when compiling without that.

Quote:

I ran your code and it works good

Did you try to use the addition feature? Because it returns like 4+78 = 13457 and such nonsense, so i thought there might be something wrong with my way of reading input as stated in my other post Smile. Try addition and see what you get. Thank's for ya time ^_^
Post 12 Apr 2007, 16:45
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 12 Apr 2007, 17:16
Here are some pionter to whats wrong,
1. First your best to have a counter var for input 1 and 2, so you know how many numbers are inputed.
2. The contverting is wrong, eg it OK for input of 1 digic eg: 8+8 etc, but will not work for say 80+80, so you need to test for 0 to 9 ,sorry only have a pmode example:
Code:
   mov   esi,string-1  ;your input that needs converting    mov   edi,subnet_mask ;your input that converted    xor   eax,eax   sip1:    inc   esi    cmp   [esi],byte '0'    jb    sip2    cmp   [esi],byte '9'    jg    sip2    imul  eax,10    movzx ebx,byte [esi]    sub   ebx,48    add   eax,ebx    jmp   sip1   sip2:    mov   [edi],al    xor   eax,eax    inc   edi    cmp   edi,subnet_mask+3    jbe   sip1    
Post 12 Apr 2007, 17:16
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 12 Apr 2007, 23:46
Some bugs:

Code:
format MZ       ;exe format
org 0x100       ;standard startpunkt (256)              
    


org 0x100 is unnecessary and confusing ... remove it, include

Code:
push cs
pop  ds 
    


----

Code:
lea dx, [endline]            
    


->

Code:
mov dx,endline
    


Both do the same, but mov is nicer and less confusing

----

Code:
endline DB 10, "$"  
    


->

Code:
endline DB 13,10, "$"  
    


----

Code:
num1 DW 16 dup 24h
num2 DW 16 dup 24h
num3 DW 0
choice DB 8 dup (0x24) ; fill with \0
res DB 0
    


->

Code:
num1: DW 0
num2: DW 0
num3: DW 0
choice: DB 8 dup (0x24) ; fill with \0
asciinum1: db 24 dup (0)
asciinum2: db 24 dup (0)
asciinum3: db 24 dup (0)
    


and rewrite the conversion Idea

The comments in Norsk or what it is are a bit annoying Sad
... and you can delete the old Attachs when uploading a new one Idea

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 12 Apr 2007, 23:46
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 24 May 2007, 06:54
Post 24 May 2007, 06:54
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:  


< 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.