News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help on Bresenham Line Algo

Started by ASMCoderD, January 05, 2010, 12:47:42 AM

Previous topic - Next topic

ASMCoderD

    .if ek < 0
        add ek, esi
    .else
        add ek, edi
        inc ecx
    .endif


Does the previous code do the following: (Pseudo code)

if ek < 0 then
ek = ek + esi
else
ek = ek + edi
ecx = ecx + 1
endif


Or does it do something else?

dedndave

it may - lol
i think "<" is for signed comparison, i.e. signed numbers
try ".lt" for less than - unsigned
you may want to check the masm manual - i am not good with these   :P

jj2007

    .if ek < 0
        add ek, esi
    .else
        add ek, edi
        inc ecx
    .endif


Sure, it should do what it seems to do. But there is a pitfall in Masm that should be displayed in fat letters on top of this forum: .if eax < 0 is never true. Try this complete little Windows application:
include \masm32\include\masm32rt.inc

signed equ sdword ptr

.code
start: mov eax, -123
.if eax<0
MsgBox 0, "Great, it's below zero", "Hi", MB_OK
.else
MsgBox 0, "You are cheating!!", "Hi", MB_OK
.endif
exit
end start


The reason is that Masm does by default unsigned comparisons:
mov eax, -123 means eax= 4294967173 - a number that is definitely above zero!!

The same happens to other DWORD variables. Fortunately, it is easy to solve this problem. Put this equate near the top of your code: signed equ sdword ptr (as shown above).

Then use .if signed ek<0, and the code will work correctly...
:thumbu

ASMCoderD

Thanks so much jj2007, that's it! Since ek < 0 was never true it wouldn't access that part of the code. I don't think I could have figured that out for a while.

Thanks!

dedndave

QuoteThanks so much jj2007, that's it!

Dave <----- chopped liver   :'(

ASMCoderD

Actually, I have one more question:

Suppose I decide to make a routine to draw a filled rectangle. Could I make it dependent on my Line routine? Would I use the invoke command? Or do I have to rewrite the whole routine?

Thanks!

jj2007

Quote from: dedndave on January 06, 2010, 12:22:22 AM
Dave <----- chopped liver   :'(
Keep cool, my friend :8)

@ASMCoderD:
You would use invoke MyLine, arg1, arg2 or whatever, similar to a call in C or Basic or Fortran. Below a simple example.

include \masm32\include\masm32rt.inc

MyTest PROTO: DWORD, :DWORD

.code
AppName db "Masm32 is great!", 0
Hello db "A message:", 0

start:
invoke MyTest, offset AppName, addr Hello
exit

MyTest proc arg1:DWORD, arg2:DWORD
; LOCAL lv1, lv2, locbuf[260]:BYTE
  MsgBox 0, arg1, arg2, MB_OK
  ret
MyTest endp

end start

ASMCoderD

Thanks. I thought it was something similar. I got all my code working now. Thanks everyone!

dedndave

lol - i am fine, Jochen   :bg
actually, i was going to refer him to you for if/while/switch/macro stuff
it's just that.................