Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

MUL, DIV

billywm664billywm664 Posts: 176Member
I've never used these before. I'm sure there's something i'm doing i'm not allowed. Basically, i want to do Y * xres + x.
All values are unsigned, xres is 640, and y and x are at max 399 and 639 respectively.


[code]
.model medium
.stack 50h
.386
.data
Xres EQU 640
offsett dd 0
curbank dw 0
bank dw 0
x dw 60
y dw 105
.code

start:

mov ax, 4F02h ;set VESA mode
mov bx, 100h ;640 x 400 x 8bit
int 10h

mov ax, 4F05h ;switch to bank 0 to start
mov bx, 0
mov dx, 0
int 10h

mov ax, 0a000h ;point to video mem
mov ds, ax

;----------------------------
;code to plot pixel. requires
;finding bank
;----------------------------
mov ax, y
mov bx, Xres
mul bx ;(y*Xres)

shl edx, 16
add edx, eax
mov offsett, edx ;result of (y*Xres) into offsett

mov ebx, 0
mov bx, x
add offsett, ebx ;finally, (y*Xres)+x is in offsett

mov [offsett], 2

mov ax, 0100h ;wait for key
int 21h
mov ax, 4c00h ;exit
int 21h

end start
[/code]

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : I've never used these before. I'm sure there's something i'm doing i'm not allowed. Basically, i want to do Y * xres + x.
    : All values are unsigned, xres is 640, and y and x are at max 399 and 639 respectively.
    :
    :
    : [code]
    : .model medium
    : .stack 50h
    : .386
    : .data
    : Xres EQU 640
    : offsett dd 0
    : curbank dw 0
    : bank dw 0
    : x dw 60
    : y dw 105
    : .code
    :
    : start:
    :
    : mov ax, 4F02h ;set VESA mode
    : mov bx, 100h ;640 x 400 x 8bit
    : int 10h
    :
    : mov ax, 4F05h ;switch to bank 0 to start
    : mov bx, 0
    : mov dx, 0
    : int 10h
    :
    : mov ax, 0a000h ;point to video mem
    : mov ds, ax
    :
    : ;----------------------------
    : ;code to plot pixel. requires
    : ;finding bank
    : ;----------------------------
    : mov ax, y
    : mov bx, Xres
    : mul bx ;(y*Xres)
    :
    : shl edx, 16
    : add edx, eax
    : mov offsett, edx ;result of (y*Xres) into offsett
    :
    : mov ebx, 0
    : mov bx, x
    : add offsett, ebx ;finally, (y*Xres)+x is in offsett
    :
    : mov [offsett], 2
    :
    : mov ax, 0100h ;wait for key
    : int 21h
    : mov ax, 4c00h ;exit
    : int 21h
    :
    : end start
    : [/code]
    :
    You shoudl use 32bit registers - if you MUL 639x399 - it will overflow 16 bit regs (max 65536):
    [code]
    mov eax, 640
    mov ecx, 400
    mul ecx ; EAX now is the offset of 640x400 (EDX erased to 0)
    [/code]


  • billywm664billywm664 Posts: 176Member
    Thanks. Like i said, all i know is what i read off the internet just before trying them out. I wrote my program with only the knowledge that the result of mul with 2 16 bit numbers goes into dx:ax... i didn't know you could just use 32 bit regs. Thanks again!

    : You shoudl use 32bit registers - if you MUL 639x399 - it will overflow 16 bit regs (max 65536):
    : [code]
    : mov eax, 640
    : mov ecx, 400
    : mul ecx ; EAX now is the offset of 640x400 (EDX erased to 0)
    : [/code]
    :
    :


Sign In or Register to comment.