hi i am a newbie here.

.IF string_input==3

.ELSEIF(al>=30)&&(al<=39)
add dl,1

.ELSEIF(bl>=30)&&(bl<=39)
add dl,1

.ELSEIF(cl>=30)&&(cl<=39)
add dl,1

.ENDIF

I want to ask is the above code for assembly equivalent to the following c++.

if(string_input==3)
{
if(al>=30)&&(al<=39)
{add dl,1;}

if(bl>=30)&&(bl<=39)
{add dl,1;}

if(cl>=30)&&(cl<=39)
{add dl,1;}
}
It suppose to be check each condition if correct add dl,1. If not dun add.If all statement correct, dl suppose to be 3.

But i can't get it rite in the assembly.Anyone plz help me......i not good at c also..so if i am wrong plz forgive me :roll:
Posted on 2004-09-16 10:37:10 by gilazilla


.IF string_input==3

.IF (al>=30)&&(al<=39)
add dl, 1
.ENDIF
.IF (bl>=30)&&(bl<=39)
add dl, 1
.ENDIF
.IF (cl>=30)&&(cl<=39)
add dl,1
.ENDIF
.ENDIF
Posted on 2004-09-16 10:53:40 by JimmyClif
I'm afraid it's not correct, the ELSEIF statement is not the equivalent of several IFs. Here's a fixed version, feel free to ask any questions and remember that the Masm32 package comes with a small MASM reference guide, with more info on high-level macros. :)


.IF string_input==3

.IF(al>=30)&&(al<=39)
add dl,1
.ENDIF

.IF(bl>=30)&&(bl<=39)
add dl,1
.ENDIF

.IF(cl>=30)&&(cl<=39)
add dl,1
.ENDIF

.ENDIF

EDIT: Sorry Jimmy, dumb me, I didn't read your post and ended up replying the exact same thing! :oops:

EDIT (AGAIN): LOL! :lol:
Posted on 2004-09-16 11:02:51 by QvasiModo
Heh, Quasi - You typed that up while I was editing :)

I realized what he wanted when I read the line "If all statement correct, dl suppose to be 3, before that I was wrong. (Just want to note that :))
Posted on 2004-09-16 11:06:02 by JimmyClif
That's not quite how we do things in assembly :P If you're going to use .IF, .ENDIF, and the like, you might as well write your program in VB.
In assembly, we would write this:
cmp string_input,3

jnz not_equal
push ecx
push eax
push ecx
push ebx
push 3
pop ecx
tstloop:
sub al,30
cmp al,10
adc dl,0
pop eax
loop tstloop
pop ecx
not_equal:

I.E. roughly half the size.

(Don't be frightened if you find it hard to follow - it usually takes a little while to become accustomed to writing good assembly code.)
Posted on 2004-09-16 11:51:18 by Sephiroth3
Good, a flame war! :twisted:
(nah, just kidding :-D )

That's not quite how we do things in assembly :P If you're going to use .IF, .ENDIF, and the like, you might as well write your program in VB.

Nonsense. There's nothing wrong with HLL macros if you know exactly what code they generate. Besides they're useful for newbies to assembly, to help reduce the learning curve.
In assembly, we would write this:
<some 133t0 azm c0d3>
I.E. roughly half the size.

OMG, a loop to replace three silly IFs??? To save a few bytes??!! :o

Ok, I admit it does look cool ;) but I'd never advise anyone to code like that, it's much harder to understand and mantain.
Posted on 2004-09-16 12:40:13 by QvasiModo
Thanks a lot guys. :) Before i could not find that answer from the book i am using.So it how to use .ELSEIF .Is it a second condition to .IF?

2.Is there a limit on the strings that could be display on the screen with the following codes?

mov esi,byteCount ; insert null terminator
mov buffer,0 ; into buffer
mov edx,OFFSET buffer ; display the buffer
call WriteString

i noticed that if ur buffer is around 3000h byte.Some of the earlier strings of words cannot be displayed. Any idea?
Posted on 2004-09-16 23:02:55 by gilazilla
gilazilla,

If you feel the "if/endif" statement too many, you can define a macro, for easier in your eyes. ex:
;================================================

if_asc09_inc MACRO reg, count
.if (reg >= "0") || (reg <= "9")
inc count ; count = count + 1
.endif
ENDM
;================================================
.code

asm_test proc string_input

.if (string_input == 3)
if_asc09_inc al, dl
if_asc09_inc bl, dl
if_asc09_inc cl, dl
.endif

ret

asm_test endp
;================================================
Posted on 2004-09-16 23:26:59 by Kestrel
i had to to do these comparison because i cannot find a way to convert numbers(decimal or hex) to strings so i can use WRITEFILE to write into a text output file.

I think u will understand this if u read my new post.At first after reading u guys solutions, i thought my problems are gone until i realised i have to write a Struct data (SYSTEMTIME) which is not a strings but DWORD.

And i dunno much about much functions available due to me studying a beginners book on assembly using MASM615. If not , i think things would be easier.

PLz have a look at my new post.
P.S . I learn a lot of things that i possibly cannot learn from that beginner book on assembly.

Thanks. :lol:
Posted on 2004-09-17 10:23:56 by gilazilla