flat assembler
Message board for the users of flat assembler.

Index > Windows > Where is the error?

Author
Thread Post new topic Reply to topic
crow78



Joined: 08 Oct 2011
Posts: 3
crow78 08 Oct 2011, 02:41
Where is the error?

Solo quiero que muestre si es par o impar// I just want to show if it is even or odd
include 'win32ax.inc'
Macro unidad3 dato
{
mov ax, dato
test ax, 01
je rpar
;test ax, 00
;jne rimpar
}

.data
ej dw 30H
; mens db 'escribe un dato', 0
; capt db 10,0, 10 dup (0)
rpar db ' result par ',0
rimpar db ' es impar ',0
titulo db 'Compilador Ensamblador FASM Programa unidad3',0

.code

start:

unidad3 [ej]
push 0
push titulo
push rimpar
push 0

push 0
push titulo
push rpar
push 0

call [MessageBoxA]
push 0
call [ExitProcess]
.end start


Lo corro pero no marca error, solo dice que provoco un error y cierra la aplicacion.// The brand run but not error, just says that caused an error and closes the application.


thanks
Post 08 Oct 2011, 02:41
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Oct 2011, 05:00
With "je rpar" you are telling the processor to execute the string rpar which will obviously crash (or at least it won't do what you might expect).

Do it like this instead:
Code:
include 'win32ax.inc'
Macro unidad3 dato
{
local ..odd, ..exit

mov ax, dato
test ax, 1
jnz ..odd

push rpar
jmp  ..exit
..odd:
push rimpar
..exit:
}

.data
ej dw 30H
rpar db ' result par ',0
rimpar db ' es impar ',0
titulo db 'Compilador Ensamblador FASM Programa unidad3',0

.code

start:

push 0
push titulo
unidad3 [ej]
push 0
call [MessageBoxA]

push 0
call [ExitProcess]
.end start    
Post 08 Oct 2011, 05:00
View user's profile Send private message Reply with quote
crow78



Joined: 08 Oct 2011
Posts: 3
crow78 09 Oct 2011, 02:09
Thank you very much, I had done differently but according to 16-bit era, so you can imagine, and the same procedures but would look like?
Post 09 Oct 2011, 02:09
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 09 Oct 2011, 02:40
Or

Code:

proc IsEven, num
push ebp
mov ebp,esp   
xor eax,eax
       bt dword[num],00
      jc _even
       inc eax
_even:
mov esp,ebp
pop ebp
ret
endp 

    
Post 09 Oct 2011, 02:40
View user's profile Send private message Reply with quote
crow78



Joined: 08 Oct 2011
Posts: 3
crow78 11 Oct 2011, 20:59
include 'win32ax.inc'
;Macro unidad3 dato
;{
;local ..odd, ..exit

;mov ax, dato
;test ax, 1
;jnz ..odd
;push rpar
;jmp ..exit
;..odd:
;push rimpar
;..exit:
;}
.data
ej dw 30H
rpar db ' result par ',0
rimpar db ' es impar ',0
titulo db 'Compilador Ensamblador FASM Programa unidad3',0

.code

start:
call IsEven,ej
push 0
push titulo
;unidad3 [ej]
push 0
call [MessageBoxA]

push 0
call [ExitProcess]
.end start
proc IsEven, num
push ebp
mov ebp,esp
xor eax,eax
bt dword[num],00
jc _even
inc eax
_even:
mov esp,ebp
pop ebp
ret
endp
Post 11 Oct 2011, 20:59
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Oct 2011, 04:36
Read this: http://flatassembler.net/docs.php?article=win32#1.3

typedef's code is both unoptimal and incorrect (the instructions dealing with EBP shouldn't be there since proc itself do that already and doing it again screws up parameter referencing). Maybe he realized you wanted homework to be solved effortlessly, MAYBE.

I'll move this thread to Windows forum as I think it has little to do with macros so far.
Post 12 Oct 2011, 04:36
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.