flat assembler
Message board for the users of flat assembler.
Index
> DOS > Read string - newbie Q |
Author |
|
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
_________________ Apprentice... Last edited by C++arl on 13 Apr 2007, 08:58; edited 2 times in total |
|||||||||||
12 Apr 2007, 14:13 |
|
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:
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 . Try addition and see what you get. Thank's for ya time ^_^ |
|||
12 Apr 2007, 16:45 |
|
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 |
|||
12 Apr 2007, 17:16 |
|
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 The comments in Norsk or what it is are a bit annoying ... and you can delete the old Attachs when uploading a new one _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
12 Apr 2007, 23:46 |
|
rugxulo 24 May 2007, 06:54
|
|||
24 May 2007, 06:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.