Re: Help, it's my first ASM homework
From: Jesse Woo (spamtrap_at_crayne.org)
Date: 11/11/04
- Next message: J. Voss: "Re: AT&T to Intel Syntax Translation"
- Previous message: Zardo: "writing windows vxd drivers with MASM/TASM"
- In reply to: Tim Roberts : "Re: Help, it's my first ASM homework"
- Next in thread: Alex McDonald: "Re: Help, it's my first ASM homework"
- Reply: Alex McDonald: "Re: Help, it's my first ASM homework"
- Reply: Tim Roberts : "Re: Help, it's my first ASM homework"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: J. Voss: "Re: AT&T to Intel Syntax Translation"
- Previous message: Zardo: "writing windows vxd drivers with MASM/TASM"
- In reply to: Tim Roberts : "Re: Help, it's my first ASM homework"
- Next in thread: Alex McDonald: "Re: Help, it's my first ASM homework"
- Reply: Alex McDonald: "Re: Help, it's my first ASM homework"
- Reply: Tim Roberts : "Re: Help, it's my first ASM homework"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|