Assembly Language: How to make a loop skip the first line?

In summary: not clear the screen then print the string... so if i clear the screen with the loop and then print the string it prints the string once over... also, the offset value is suppose to be stored in the same floor as the buffer but it's not... it's stored in the same offset as the program's start up code which is in a different floor... so yeah.
  • #1
mimzy
6
0
Hello, so i have a problem with my assembly code. I want to clear the screen of the DOS and display the string input in the first line. I decided to make a loop that will run 2000 times and fill the space with [20H, which is the ascii for space bar] however, It clears out my message as well and I thought of skipping the first 40 loops so that it'll leave my string[max 40 chars] as it is and proceed to clear my screen; however, I've tried many ways but I can't get it right D: here's here code i have atm

MOV DX,OFFSET BUF1 ; OFFSET=STORE IN THE SAME FLOOR "BUF1"
MOV BUF1,40 ; MAX CHARACTERS IN BUF1 = 40

MOV AH,0AH ; READS ONE LINE FROM KEYBOARD
INT 21H

[this is not relevant, it just creates, writes, reads, and closes a file lol :P but i thought it might help a little D:]
MOV AH,3CH ; CREATION 3CH
XOR CX,CX
MOV DX,OFFSET FILE1
INT 21H ; CREATION FILE END

MOV BX,AX
MOV AH,40H ; WRITING 40H
MOV CX,40 ; MAX WRITING SIZE = 40
MOV DX,OFFSET BUF1
INT 21H ; WRITING FILE END

MOV AH,3EH
INT 21H ; CLOSE FILE

MOV AH,3DH ; OPEN 3DH
MOV AL,0
MOV DX,OFFSET FILE1
INT 21H ; OPEN FILE END
MOV BX,AX

MOV AH,3FH ; READING 3FH
MOV CX,40 ; MAX CHARACTERS READ = 40
MOV DX,OFFSET BUF2
INT 21H ; READING FILE END

MOV AH,3EH ; CLOSE 3EH
INT 21H ; CLOSE FILE END
MOV DX,OFFSET BUF2
MOV AH,0AH
INT 21H
MOV CX,2000 ; START OF CLEARING RUN LOOP 2000 TIMES

LUCY: MOV AH,06H ; START OF LOOP, CALL DISPLAY FUNCTION 06H
MOV DL,20H ; 20H=' ' [SPACE IN ASCII]
INT 21H
LOOP LUCY ; LOOP END

I know Assembly Code isn't very popular :( that's why it's so hard to find a solution for my problem Q.Q and i have to seek for help here. If no one knows it, ill understand :c

thanks :D
 
Technology news on Phys.org
  • #2
Hi mimzy
You are making your life unnecessarily hard :smile:
You are in a DOS box, so the right way to do it is to
1) clear the string with an interrupt call
2) print your message with another one

Here is a list of interrupt calls you might find useful
 
  • #3
well the thing is that i need to print the string on the first line of the dos... so i was thinking of printing it and then clearing it; however, when I clear it, it clears from the beginning... so yeh. Also, I need to use this method since it's the only way our professor has shown us so far D:
 
  • #4
mimzy said:
Hello, so i have a problem with my assembly code. I want to clear the screen of the DOS and display the string input in the first line. I decided to make a loop that will run 2000 times and fill the space with [20H, which is the ascii for space bar] however, It clears out my message as well and I thought of skipping the first 40 loops so that it'll leave my string[max 40 chars] as it is and proceed to clear my screen; however, I've tried many ways but I can't get it right D: here's here code i have atm

MOV DX,OFFSET BUF1 ; OFFSET=STORE IN THE SAME FLOOR "BUF1"
MOV BUF1,40 ; MAX CHARACTERS IN BUF1 = 40

MOV AH,0AH ; READS ONE LINE FROM KEYBOARD
INT 21H

Run your loop to print a space character at each position of the window, and then print your input string. I don't understand why clearing the screen should also clear your input string.

In the first line of code above, you have this comment: OFFSET=STORE IN THE SAME FLOOR "BUF1". What does that mean, particularly "in the same floor"?

You also need to keep in mind that the 0Ah function of int 21h returns a buffer with the first byte being the number of bytes to read, and the second byte being the number of bytes actually read. You probably don't want to print those two bytes on the screen.
 
  • #5
If you want the line at the top of the screen, then why not write the line, followed by hex 0D (carriage return), then followed by 19 hex 0A (line feed)? This will end up putting the cursor at the bottom of the screen though (unless you turn the cursor off, or use other instructions to reset the cursor location).
 
  • #6
mimzy said:
MOV DX,OFFSET BUF2
MOV AH,0AH
INT 21H
MOV CX,2000 ; START OF CLEARING RUN LOOP 2000 TIMES

LUCY: MOV AH,06H ; START OF LOOP, CALL DISPLAY FUNCTION 06H
MOV DL,20H ; 20H=' ' [SPACE IN ASCII]
INT 21H
LOOP LUCY ; LOOP END

A couple of comments on your code...

1. Why do you have BUF2?
2. Your label LUCY should be something more meaningful in relation to your program, not the name of a friend or girlfriend or whatever.
 
  • #7
Mark44 said:
Run your loop to print a space character at each position of the window, and then print your input string. I don't understand why clearing the screen should also clear your input string.

In the first line of code above, you have this comment: OFFSET=STORE IN THE SAME FLOOR "BUF1". What does that mean, particularly "in the same floor"?

You also need to keep in mind that the 0Ah function of int 21h returns a buffer with the first byte being the number of bytes to read, and the second byte being the number of bytes actually read. You probably don't want to print those two bytes on the screen.

it does show once the screen is cleared with the loop and then print the string but the assignment was to print the string on the first line so I'm just trying to stick to what I've been asked to be done D: although it does work in the way u described.

the comment i made on the offset was because someone had told me that it meant to store a set of data let's say, in the same "floor" as buf1, as in the data will not be scattered around... It doesn't rly have much to do with the line of code next to it, it was just to remind me of what offset meant :P unless that person gave me incorrect info xD

and lastly, I'm not quite sure what u meant but i think u mean the 1 byte of space that stores the max number of bytes and the other 1 byte that stores the min number of bytes? if so then both buf1&buf2 are given the value of 42 in the data segment o.o ... i think i should have posted the entire code here Dx my bad :(

rcgldr said:
If you want the line at the top of the screen, then why not write the line, followed by hex 0D (carriage return), then followed by 19 hex 0A (line feed)? This will end up putting the cursor at the bottom of the screen though (unless you turn the cursor off, or use other instructions to reset the cursor location).

hmm that makes sense o,o but how can I make the loop skip that line if the loop starts looping [clearing with space] from the very first line of the command prompt D:?

Mark44 said:
A couple of comments on your code...

1. Why do you have BUF2?
2. Your label LUCY should be something more meaningful in relation to your program, not the name of a friend or girlfriend or whatever.

oh.. well I was told[again lol] that since this program needed to be closed and then read, we had to use a different buffer to read it? Dx
oh and and loop name was my real name mimi but i felt kinda weird posting it up with my name so i took an anime character's name instead XD (kinda silly XD but i'll follow ur suggestion next time ^-^)

Thanks a lot for all ur responses! and sorry for my ignorance about assembly language, my class and I have only covered so much Dx I feel kinda embarrassed for not having enough knowledge to answer ur questions about my own code :(
 
  • #8
mimzy said:
it does show once the screen is cleared with the loop and then print the string but the assignment was to print the string on the first line so I'm just trying to stick to what I've been asked to be done D: although it does work in the way u described.

the comment i made on the offset was because someone had told me that it meant to store a set of data let's say, in the same "floor" as buf1, as in the data will not be scattered around...
I still don't get what you mean by "floor." A floor is a surface in a building that you walk on, and I don't see how that connects with computer memory.

mimzy said:
It doesn't rly have much to do with the line of code next to it, it was just to remind me of what offset meant :P unless that person gave me incorrect info xD
Maybe they were pulling your leg.

You should try to get into the practice of putting in comments that are related to the code next to them. It's fine to put in something to help you remember what you're doing, but it should be related to the code in some way.
mimzy said:
and lastly, I'm not quite sure what u meant but i think u mean the 1 byte of space that stores the max number of bytes and the other 1 byte that stores the min number of bytes? if so then both buf1&buf2 are given the value of 42 in the data segment o.o ... i think i should have posted the entire code here Dx my bad :(
The first byte is the number of bytes you want to read, at most; the second byte is put there by DOS, and it is the number of bytes it read.

You'll confuse yourself if you try to use two buffers to input one string of characters, so you should get rid of BUF2.
mimzy said:
hmm that makes sense o,o but how can I make the loop skip that line if the loop starts looping [clearing with space] from the very first line of the command prompt D:?
I don't know why you need to. What you said in your first post was "I want to clear the screen of the DOS and display the string input in the first line." Why do you think you need to skip over some text?
mimzy said:
oh.. well I was told[again lol] that since this program needed to be closed and then read, we had to use a different buffer to read it? Dx
I would stop listening to whoever is telling you this stuff.
mimzy said:
oh and and loop name was my real name mimi but i felt kinda weird posting it up with my name so i took an anime character's name instead XD (kinda silly XD but i'll follow ur suggestion next time ^-^)
It doesn't matter if it was your name or some cartoon character - it's not a good name for a label. Your instructor is liable to deduct points for using a meaningless (and therefore silly) label name.

The biggest reason for choosing variable names and labels and writing meaningful comments is to help whoever comes along next understand your program. They also help you understand you code better if you look at it a few days, weeks, or months after you wrote it. If you want to appear professional, don't choose dumb names for variables, PROCs, labels, etc.
mimzy said:
Thanks a lot for all ur responses! and sorry for my ignorance about assembly language, my class and I have only covered so much Dx I feel kinda embarrassed for not having enough knowledge to answer ur questions about my own code :(

Don't feel bad - assembly language is hard, and it's OK to feel ignorant about something when you're trying to learn it! There are advantages, though, one of which is that you get an intimate understanding of what is happening in the computer's CPU.
 

1. How do I make a loop skip the first line in assembly language?

To make a loop skip the first line, you can use a conditional jump instruction such as JNE or JNZ to skip over the first line of the loop. This instruction will check if a certain condition is met, and if it is not, the program will jump to the specified location instead of executing the first line of the loop.

2. Can I use a counter to skip the first iteration of a loop in assembly language?

Yes, you can use a counter variable to control the number of iterations in a loop. You can initialize the counter to start at 2 instead of 1, and then use a conditional jump instruction to check if the counter has reached the desired number of iterations before executing the first line of the loop.

3. How do I modify an existing loop to skip the first line in assembly language?

To modify an existing loop to skip the first line, you can add a conditional jump instruction before the first line of the loop. This instruction will check if the desired condition is met, and if not, it will jump to the next line of the loop instead of executing the first line.

4. What is the benefit of skipping the first line in a loop in assembly language?

Skipping the first line in a loop can be beneficial in situations where the first line is not necessary or needs to be skipped based on a certain condition. This can save processing time and improve the efficiency of the program.

5. Are there any other ways to skip the first line in a loop besides using a conditional jump instruction in assembly language?

Yes, there are other ways to skip the first line in a loop, such as using a FOR loop with a counter variable starting at 2, using a REPEAT loop with a counter variable starting at 1 and using a conditional jump instruction to skip the first line, or using a COUNTDOWN loop with a counter variable starting at 2 and using a conditional jump instruction to skip the first line. The best method to use will depend on the specific requirements of your program.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
20
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
7
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
20
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
Back
Top