Jump to content

Assembly 8086 how to stop at certain number of columns when looping pixels?

Dusteh
    org  100h        mov ah, 0   ; set display mode function.    mov al, 13h ; mode 13h = 320x200 pixels, 256 colors.    int 10h     ; set it!        setrow db '50'    setcol db '50'        mov ax, setcol    mov bx, setrow    mov cx, 10  ; column    mov dx, 20  ; row    mov al, 15  ; white    mov ah, 0ch ; put pixel    int 10h            addpixel:    inc cx    int 10h        cmp ax,cx        JNE addpixel    ret

I have my code written in assembly 8086, the pixels generate infinitely and I want to generate it for 50 times and make the program stop.

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm.. Long time since I've done assembly.

 

However i think there is a instruction called LOOP or LOOPE, that loops while cx is either 0 or not (can't remember which one).

 

Hope that helps.

 

EDIT: Also i think the usage of cx to hold an value for the columns is bad practice?

Best regards Zahlio,
Unity asset developer - Game developer (http://playsurvive.com) - Computer Science student

Link to comment
Share on other sites

Link to post
Share on other sites

You're clobbering ax with your BIOS interrupt call. You set it to setcol, and then immediately overwrite that value (why is 50 in quotes?). ax is set to 0C15h (3093) when the cmp happens. What are setrow and setcol supposed to be for?

 

Why do you have a ret instruction at the end? ret pops an address from the stack and jumps to it. Typically paired with a call (which pushes the current IP onto the stack for ret to pop).

 

 

 

Protip: In mode 13h, don't bother using the BIOS interrupts to draw. It's crazy slow. You can access the memory directly.

 

I'm assuming this is NASM.

 

For copying a value multiple times into a linear piece of memory you can use "rep stosb" or "rep stosw", for byte and words respectively. It repeats the stosb/w instruction until cx is 0. stosb/w (store-single-byte/word) copies ax to the memory pointed at [es:di].

 

This is a basic example that just draws to the start of the 0A000h segment

    [org     100h]    push    word 0A000h    pop     es                              ;set extra segment register to start of VGA memory            xor     ax, ax                      mov     al, 13h                        int     10h        mov     cx, 50                          ;number of times to repeat    mov     al, 15                          ;palette index    xor     di, di                          ;clear di to start draw at beginning of video mem        rep     stosb                           ;copy into memory at [es:di], di increments after each call    

You can write a routine to calculate the offset into memory. Here is one I wrote for writing to the VGA color text memory at B800h

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    VGA Offset    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; vga_get_char_offset:                    ;bx parm. bl - x, bh - y. ret - offset in di     push    ax                          ;push ax and dx onto stack    push    dx                          ;we don't want to clobber them       xor     dx, dx    mov     al, bh                      ;put y value into al    mul     byte [console_w]            ;y * row_width. mul requires register or memory operand    mov     dl, bl                      ;put x value into dl    add     ax, dx                      ;add x + y_row offset    mov     di, ax                      ;move to di for our return value    shl     di, 1                       ;offset * 2, chars occupy 2 bytes               pop     dx                          ;restore ax and dx    pop     ax       ret   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

Fuk I should really get around to learning code ay?

In the grim darkness of the far future, there is only a GTX 1080, just a single 1080, where my glorious PC once stood....

For that is all I need, For the Emperor of Man, Jen-Hsun Huang, protects. We march for Nvidia, and we shall know no fear!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×