ASSEMBLY Programming..

  • Hi.. Does anyone know how to clear screen in Assembly?

    In C programming...
    #include
    main()
    {
    clrscr();
    }


  • Hi there,

    Try the following code which uses BIOS interrupts: PUSHA ; save register content
    XOR EAX, EAX ;clear
    XOR EBX, EBX ;clear
    XOR ECX, ECX ;clear
    XOR EDX, EDX ;clear
    MOV AH, 6 ; use subfunction 6 of int 10h
    MOV DX, 174fh ; size to clear (changes depending on screen size)
    INT 10h ; call interrupt
    POPA ; restore registers

    Remember you can't use the BIOS interrupts in protected mode.

    Let me know how you go.
    Cheers


  • Can you please post your whole program? Hard to help when I can't see the whole thing :)

    It could be the protected mode thingy I was talking about. If i can see your code then I can help you with the issue.


  • the kirupa forum is web technology-centric. don't expect much expertise for assembly, c++ from this forum.

    Never assume ;) There's more knowledge here in this area than you think.

    lairusi: what architecture are you writing your ASM for? x86? x64? What assembler are you using? TASM/FASM/etc?? Are you using Windows or Linux?


  • Are you winding me up?


  • the kirupa forum is web technology-centric. don't expect much expertise for assembly, c++ from this forum.

    try
    http://www.codeguru.com/forum/forumdisplay.php?f=69


  • The code I gave you was FASM specific. Using it in NASM will not work, because the setup/syntax is slightly different. You need to just take the bits that you need. That is, to clear the screen use:
    ; clear the screen
    mov ah, 6 ; Use function 6 - clear screen
    mov al, 0 ; clear whole screen
    mov bh, 7 ; use black spaces for clearing
    mov cx, 0 ; set upper corner value
    mov dl, 79 ; coord of right of screen
    mov dh, 24 ; coord of bottom of screen
    int 10h ; go!and to set the cursor to the top left of the screen use:; move the cursor to the top of the screen
    mov ah, 2 ; use function 2 - go to x,y
    mov bh, 0 ; display page 0
    mov dh, 0 ; y coordinate to move cursor to
    mov dl, 0 ; x coordinate to move cursor to
    int 10h ; go!Try putting those two snippets in your own application and see how you go.


  • *CLAP CLAP CLAP CLAP CLAP*

    YAAAAAAAAAAAAAAAAAAAAAY!!!!!!!!

    *MEXICAN WAVE*

    I am so unbelievably impressed that this was at least attempted with an answer..... Well Done!:beam:


  • Sorry.. Might I ask, is the code in 16-bit mode? If it is, are there any difference in the code if it is in 32-bit?

    I have tried to copy pasted the code in the notepad and assembled it the same way as it is in the earlier post and it returns, clearscreen.asm:6: error: parser: instruction expected


    Thank you very much for your patience.. :)


  • Hi all,

    Sorry, I might have been wrong with my instructions in the previous post. I had a quick play with some ASM to make sure that I didn't mislead you again. Here's a sample program written for FASM, it clears the screen as you'd expect:
    ; fasm example of writing 16-bit COM program

    org 100h ; code starts at offset 100h
    use16 ; use 16-bit code

    display_text = 9

    ; fill the screen with some crap
    mov ah, display_text
    mov dx, hello
    int 21h
    int 21h
    int 21h
    int 21h
    int 21h
    int 21h
    int 21h
    int 21h
    int 21h

    ; clear the screen
    mov ah, 6 ; Use function 6 - clear screen
    mov al, 0 ; clear whole screen
    mov bh, 7 ; use black spaces for clearing
    mov cx, 0 ; set upper corner value
    mov dl, 79 ; coord of right of screen
    mov dh, 24 ; coord of bottom of screen
    int 10h ; go!

    ; move the cursor to the top of the screen
    mov ah, 2 ; use function 2 - go to x,y
    mov bh, 0 ; display page 0
    mov dh, 0 ; y coordinate to move cursor to
    mov dl, 0 ; x coordinate to move cursor to
    int 10h ; go!

    int 20h

    hello db 'Hello world!',24h
    The code will be slightly different for you using NASM, but the core of it (the clear screen and moving the cursor back to the top of the screen), should be exactly the same.

    Hope that helps


  • Hi there,

    Try the following code which uses BIOS interrupts: PUSHA ; save register content
    XOR EAX, EAX ;clear
    XOR EBX, EBX ;clear
    XOR ECX, ECX ;clear
    XOR EDX, EDX ;clear
    MOV AH, 6 ; use subfunction 6 of int 10h
    MOV DX, 174fh ; size to clear (changes depending on screen size)
    INT 10h ; call interrupt
    POPA ; restore registers

    Remember you can't use the BIOS interrupts in protected mode.

    Let me know how you go.
    Cheers

    Thank you for your reply Colonial.. And apologies for my late reply... I have tried your code and unfortunately (or I think) it's not working... Did I do something wrong?

    I run command prompt then, typed the ff. to assemble the code:
    nasm -o fibo.com -f bin fibo.asm
    then after compiling,
    i typed fibo. Then, it produced

    http://img379.imageshack.us/img379/7366/errorwe1.png


  • no, but i could do if you wanted.... :D


  • Oh... ok... Thanks! =)


  • Hi.. Does anyone know how to clear screen in Assembly?

    In C programming...
    #include
    main()
    {
    clrscr();
    }


    This is probably the the single hardest question I've ever seen in a forum :hugegrin:
    You haven't mentioned what platform you are using, which makes this question impossible to answer. ASM is CPU specific, which means that although most opcodes/mnemonics are basically the same, the subtle differences that are there, will most likely kill any none specific implementation.

    Roughly:
    First you need to figure out a way to get access to the memory dump off the screen. This depends heavily on what platform you are working on.
    Once you have the address of the screen data, its just a question about writing zeros to it.

    But seriously though ... i rather doubt you will be able to write an asm function that is more efficient than the above C code yourself, so why bother ;)


  • I have tried your codes and it worked!

    Thank you very much!!!! :bounce:


  • Never assume ;) There's more knowledge here in this area than you think.

    lairusi: what architecture are you writing your ASM for? x86? x64? What assembler are you using? TASM/FASM/etc?? Are you using Windows or Linux?

    I'm using Windows. NASM, x86, 32-bit. I hope I answered your questions correctly. =) I'm still grasping the concept of this programming language.

    Thanks!


  • You're welcome :) I'm glad I could help.

    I'd just like to say that I highly recommend reading that code over and over until you understand what's going on. There's plenty of documentation on the Internet about the interrupts that you're using, and you should make sure that the code makes sense. There are comments there to help you understand. Promise me you'll make the effort to do that, because code regurgitation is a bad thing if you don't understand what's going on! :)

    Good luck with the rest of your project.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about ASSEMBLY Programming.. , Please add it free.

    Characteristics of Adult Bully Targets China Portfolio Insurance