Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Another Assembly Question

Posted on 1997-05-04
5
Medium Priority
?
533 Views
Last Modified: 2008-03-17
I am trying to learn to use assembly and am trying to make a fuction to
draw a pixel to unsigned char far *double buffer using an external
assembly function. and i cant get it to work right. This is what i have
so far and it gives me 2 errors.

; AsmPixel(int x, int y, int value)

Parms struc
         dw    2 dup(?)
x        dw    ?
y        dw    ?
value    dw    ?
Parms ends

    .model   small
    .386
    .code
    public _AsmPixel

extrn _double_buffer:word
ES:DI -> double_buffer

_AsmPixel    proc    near
      push   bp
      mov    dx, 320   ; Put 320 in DX
      mul    dx        ; multiply AX (Y) by DX (320)
      add    ax, bx    ; add BX (X) to AX -> 320*y+x
      add    di, ax    ; add to pointer offset ***
                   
;ES:DI now points at &double_buffer[320*y+x]
     
      mov    es:[di], cl ; Store the byte
_AsmPixel      endp
0
Comment
Question by:Doug8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1250246
What are the errors??
Are you sure ES:DI contains the adress of the buffer? shouldn't you load the adres with lea ?
A good trick is: write it in C and compile to assembly, and use it as a starter.
.luc.
0
 

Author Comment

by:Doug8
ID: 1250247
The errors are end of file found and symbol already different kind on the line of ES:DI-> double_buffer. And i dont know if it contains the address of double_buffer and i dont know the statement lea. Thanx for the suggestion.
0
 
LVL 3

Expert Comment

by:rmichels
ID: 1250248
Don't you need  "end" at the end of file.  That should fix the eof error.    It's been awhile for me in ASM but don't you need

mov byte ptr es:[di],cl  (byte ptr added)?



0
 

Author Comment

by:Doug8
ID: 1250249
Adjusted points to 70
0
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 140 total points
ID: 1250250
I thought ES:DI->double_buffer was not part of you asm file but just a remark (I thougt you forgot the ';' ). It sure isn't assembly. If you want to load a adress into a segment:offset registerpair you should use one of the le.. instructions (lea lds les) these instructions load the segment register with the correct segment and then loads the offset in a register.
For example:
les di, _double_buffer
loads the es segmentregister with the segment of _double_buffer and the di register with the offset.
Finally: you use registers to pass variables to your function, this is ok internally but you can't call your function from C or an other language. If you want to interface with an prog.language like C I recommend that you write the function in C and then compile it to assembly (most compiler have an option for this)
Use the assembly the compiler generates as a starter. I always use this methode. It's fast and bugfree.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question