Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jun 4, 2012 #1
    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 cant 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
     
  2. jcsd
  3. Jun 4, 2012 #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
     
  4. Jun 4, 2012 #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:
     
  5. Jun 4, 2012 #4

    Mark44

    Staff: Mentor

    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.
     
  6. Jun 4, 2012 #5

    rcgldr

    User Avatar
    Homework Helper

    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).
     
  7. Jun 4, 2012 #6

    Mark44

    Staff: Mentor

    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.
     
  8. Jun 4, 2012 #7
    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 lets 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 :(

    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:?

    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 :(
     
  9. Jun 5, 2012 #8

    Mark44

    Staff: Mentor

    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.

    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.
    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.
    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?
    I would stop listening to whoever is telling you this stuff.
    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.
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Assembly Language: How to make a loop skip the first line?
  1. Assembly language (Replies: 5)

  2. Assembly language or C (Replies: 5)

  3. New to assembly language (Replies: 12)

Loading...