Re: Help, it's my first ASM homework

From: Jesse Woo (spamtrap_at_crayne.org)
Date: 11/11/04


Date: Thu, 11 Nov 2004 18:23:21 +0000 (UTC)

Tim Roberts wrote:
> Jesse Woo <spamtrap@crayne.org> wrote:
>
>>Hi, my first post here. I am really confused why my program does not
>>run correctly, it's my first assignment that counts the digits and
>>letters in the string you input. Could someone point out the bug?
>>thanks. (compiled by MASM5.1 in FreeDOS in Bochs)
>
>
> Holy cripes, aren't ANY of the introductory programming classes teaching
> comments any more? There's NO WAY you should be allowed to write a
> 150-line assembly language program without a SINGLE comment.
>
thank you for the reminder of comments, yes, my class does fail in
teaching us a good programming habit either in C programming course or
in ASM course. In my opinion I think comments is a need only in "big"
projects that involved several people, as a homework program, teacher
only care about the result. In addition, I like fooling teachers. :P
>
>>=== code start here ===
>>...
>> MOV CH, 0
>> MOV CL, BUF_ACT
>> MOV BUF_A, CL
>> LEA SI, BUF_ACT
>>MAIN: INC SI
>> MOV AL, [SI]
>> MOV BL, 30H
>> MOV BH, 3AH
>> CMP AL, BL
>> JS OTHER
>> CMP AL, BH
>> JNS CAP
>> INC BUF_B
>> LOOP MAIN
>> JMP PRINT
>
>
> OK, so if the character is a digit, you bump BUF_B, decrement the loop
> counter, and if the loop isn't finished, you jump back to MAIN to do
> another character.
>
>
>>CAP: MOV BL, 41H
>> MOV BH, 5BH
>> CMP AL, BL
>> JS OTHER
>> CMP AL, BH
>> JNS LOWER
>> INC BUF_C
>> JMP MAIN
>
>
> Here, if the character is an upper-case letter, you bump BUF_C, and
> unconditionally jump back to MAIN. Do you see the problem? What happens
> to your loop counter in this branch?
>
> Answer: nothing. If you enter six characters, the loop will keep counting
> until it finds six decimal digits, regardless of how many letters and
> garbage characters it finds in the meantime.
>
> Change your JMP MAIN's to jump back to the LOOP MAIN instructions, AFTER
> you go back and add some comments so you can figure out what this program
> is doing two weeks from now.
I see what goes wrong now, thank you for your time to read this
uncommented 150-line code.

-- 
- Jesse Woo, jessew@gmail.com


Relevant Pages

  • Re: Help, its my first ASM homework
    ... >Hi, my first post here. ... OK, so if the character is a digit, you bump BUF_B, decrement the loop ... unconditionally jump back to MAIN. ...
    (comp.lang.asm.x86)
  • Generating sequence of AlphaNumber
    ... I am having trouble generating a sequence of numbers from the following start ... what I have done so far is loop through each character and check if its a ... But when I increment the digits, its strips of the leading zeros. ...
    (php.general)
  • Re: looking for implementation of strtok
    ... contains a ',' character. ... we enter the ugly loop that simply implements strspn: ... loop sets spanp to delim, then loops while seting sc (the "span ... If there are no more tokens, we set *lastp to NULL (this is, I ...
    (comp.lang.c)
  • Re: Effective/Proper use of "regular expressions"
    ... parenthesized elements in your regular expression, ... from the set (unless the first character in the bracket expression is ... The range 0-9 is the set of all digits, ... a literal period followed by one or more digits". ...
    (comp.lang.tcl)
  • Re: inputting the ephemerides (SOLUTION!)
    ... the user manual input of control data, or the use of a control record, ... Somewhere along the way, I've lost the last float, which Terence calls F3. ... C STOPS ON TRAILING BLANK OR CHARACTER ... C NOW ONLY DIGITS ...
    (comp.lang.fortran)