flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > what takes so long?

Author
Thread Post new topic Reply to topic
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
what's wrong? my code compiles in 5 seconds on my computer, and it runs after a quite large execution delay while freezing my system.

Code:
macro textcolor _reg,_rf,_gf,_bf,_lf,_rb,_gb,_bb,_lb ; byte register fore:RGBL Back:RGBL
{
light=1000b
red=100b
green=10b
blue=1
back=(_lb shl 3)+(_rb shl 2)+(_gb shl 1)+(_bb)
fore=(_lf shl 3)+(_rf shl 2)+(_gf shl 1)+(_bf)
_color=fore+(back shl 4)
;wordcolor=color shl 8
;dwordcolor=(wordcolor shl 16) or wordcolor
 mov _reg,_color and $ff}

macro bdisplay _stringpointer001
{ mov si, _stringpointer001
  call bwritestring }
k_up=  $48e0
k_down=$50e0
k_esc= $011b
k_enter=$1c0d

menuxypos=$0505
org 256

push es
push $b800
pop es

mainloop:

mov bx,menuxypos
mov cx,7
.drawmenu:
push cx
movzx edx,cx
dec edx
movzx eax,byte [mainmenu_choicepointer]
textcolor ch,0,1,0,0,0,0,0,0 ; byte register fore:RGBL Back:RGBL
cmp ax,dx
jne .no_highlight
textcolor ch,1,1,1,0,0,1,0,0 ; byte register fore:RGBL Back:RGBL
.no_highlight:
mov si,[menuelements_pointer_array+2*edx]
push bx
call writestring80x25 ; DS:SI = address of string bl=x bh=y ch=color , 0 terminated string !
pop bx
inc bh
pop cx
loop .drawmenu

call breadkey  ;returns: AH = BIOS scan code AL = ASCII character note: enhanced

cmp ax,k_enter
jne .not_enter
movzx ebx,byte [mainmenu_choicepointer]
lea ebx,[menuelements_pointer_array_procedure_pointers+2*ebx]
call word [bx]
jmp mainloop
.not_enter:
cmp ax,k_up
jne .not_up

cmp byte [mainmenu_choicepointer],6
jae .notinc
inc byte [mainmenu_choicepointer]
.notinc:

jmp mainloop
.not_up:
cmp ax,k_down
jne .not_down
cmp byte [mainmenu_choicepointer],0
jz .notdec
dec byte [mainmenu_choicepointer]
.notdec:
jmp mainloop
.not_down:
cmp ax,k_esc
jne mainloop ; jmp mainloop
push ax
exit_proc:
pop ax
pop es
int 20h

mainmenu_choicepointer: db 6

menuelements_pointer_array_procedure_pointers: dw exit_proc,spdtest,_lock,chiperase,program,erase_program,erase_program_lock
menuelements_pointer_array: dw .m01,.m02,.m03,.m04,.m05,.m06,.m07
.m01: db 'EXIT',0
.m02: db 'Communication Speed Test',0
.m03: db 'Lock',0
.m04: db 'Chip Erase',0
.m05: db 'Program',0
.m06: db 'Erase & Program Only',0
.m07: db 'Erase & Program , then Lock',0

printer_adresses: dw $278,$378,$3bc,0 ; {printerport base addresses}

global_base_address: dw $378
global_port_data_buffer: db 0

breadkey:  ;returns: AH = BIOS scan code AL = ASCII character note: enhanced
mov ah,$10
int $16
ret

bgotoxy: ; dl=x, dh=y ( 0,0 = upper left ) RETURNS:  AX,BX,DX = undefined.
push ax dx ; transparency
mov ah,2
xor bh,bh
int 10h
pop dx ax
ret

output_databyte: ; al to parallel port, ba=base adress
mov dx,global_base_address
out dx,al
ret

bwritestring: ; Writes a 0 terminated string to screen ( string is at ds:si )
push ax bx
mov bx,7 ; use video page 0, normal white
mov ah,$e
localloop:
lodsb
or al,al
jnz next_char
pop bx ax
ret
next_char:
int 10h
jmp localloop

writestring80x25: ; DS:SI = address of string bl=x bh=y ch=color , 0 terminated string !
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

.again:
mov ah,ch
lodsb
or al,al
jz .ext2
stosw
jmp .again
.ext2:
ret

highlightbackground: ; eax = dword color
xor di,di
mov cx,1000
.setback:
and dword [es:di],$00ff00ff
or dword [es:di],eax
add di,4
loop .setback
ret


bwritedword: ; EAX = number, BL = base
  push eax ebx ecx edx
  and ebx,$ff
  cmp bl,2 ; base can't be less than 2 Smile
  jge .start
  mov bl,10     ; using bx = 10 instead
  .start:
  xor ecx,ecx     ; cx = 0
  .new:
  xor edx,edx     ; dx = 0
  div ebx        ; number / base
  push dx       ; push the remainder
  inc ecx        ; increase the "digit-count"
  or eax,eax      ; if the quotient still is not 0, do it once more
  jnz .new
  .loop:
  pop ax        ; pop the remainder
cmp al,10
sbb al,69h
das
mov ah,$e
int 10h
  loop .loop
  pop edx ecx ebx eax
ret

cls80x25t: ; clear the text screen really fast
xor eax,eax
mov di,ax
mov eax,$07200720
mov cx,1000
rep stosd
ret

;bitswap: ; swap bits in al
;mov ah,al
;xor al,al
;mov cx,8
;@l0:
;shl al,1
;shr ah,1
;adc al,0
;loop @l0
;ret

bitswap: ; swap bits in al
mov ah,al
xor al,al
mov cx,8
@l0:
shl al,1
rcr ah,1
loop @l0
ret

spdtest:
call display_currentproc
ret
_lock:
call display_currentproc
ret
chiperase:
call display_currentproc
ret
program:
call display_currentproc
ret
erase_program:
call display_currentproc
ret
erase_program_lock:
call display_currentproc
ret

display_currentproc:
movzx ebx,byte [mainmenu_choicepointer]
bdisplay [menuelements_pointer_array+2*ebx]
call breadkey
ret
    
Post 02 Dec 2004, 02:00
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
after i re write it without
Code:
k_up=  $48e0
k_down=$50e0
k_esc= $011b
k_enter=$1c0d
    

and every macro, it complies just fine, and runs immediately
Code:
org 256

push es
push $b800
pop es
mainloop:

mov bx,$0505
mov cx,7
.drawmenu:
push cx
movzx edx,cx
dec edx
movzx eax,byte [mainmenu_choicepointer]
mov ch,$3
cmp ax,dx
jne .no_highlight
mov ch,$12
.no_highlight:
mov si,[menuelements_pointer_array+2*edx]
push bx
call writestring80x25 ; DS:SI = address of string bl=x bh=y ch=color , 0 terminated string !
pop bx
inc bh
pop cx
loop .drawmenu

call breadkey  ;returns: AH = BIOS scan code AL = ASCII character note: enhanced

cmp ax,$1c0d
;cmp ax,k_enter
jne .not_enter
movzx ebx,byte [mainmenu_choicepointer]
call word [menuelements_pointer_array_procedure_pointers+2*ebx]
jmp mainloop
.not_enter:
cmp ax,$48e0
;cmp ax,k_up
jne .not_up

cmp byte [mainmenu_choicepointer],6
jae .notinc
inc byte [mainmenu_choicepointer]
.notinc:

jmp mainloop
.not_up:
cmp ax,$50e0
;cmp ax,k_down
jne .not_down
cmp byte [mainmenu_choicepointer],0
jz .notdec
dec byte [mainmenu_choicepointer]
.notdec:
jmp mainloop
.not_down:
cmp ax,$011b
;cmp ax,k_esc
jne mainloop ; jmp mainloop


push ax
exit_proc:
pop ax
pop es
int 20h

mainmenu_choicepointer: db 6

menuelements_pointer_array_procedure_pointers: dw exit_proc,spdtest,_lock,chiperase,program,erase_program,erase_program_lock
menuelements_pointer_array: dw .m01,.m02,.m03,.m04,.m05,.m06,.m07
.m01: db 'EXIT',0
.m02: db 'Communication Speed Test',0
.m03: db 'Lock',0
.m04: db 'Chip Erase',0
.m05: db 'Program',0
.m06: db 'Erase & Program Only',0
.m07: db 'Erase & Program , then Lock',0

writestring80x25: ; DS:SI = address of string bl=x bh=y ch=color , 0 terminated string !
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

.again:
mov ah,ch
lodsb
or al,al
jz .ext2
stosw
jmp .again
.ext2:
ret

bwritestring: ; Writes a 0 terminated string to screen ( string is at ds:si )
push ax bx
mov bx,7 ; use video page 0, normal white
mov ah,$e
localloop:
lodsb
or al,al
jnz next_char
pop bx ax
ret
next_char:
int 10h
jmp localloop

breadkey:  ;returns: AH = BIOS scan code AL = ASCII character note: enhanced
mov ah,$10
int $16
ret

spdtest:
call display_currentproc
ret
_lock:
call display_currentproc
ret
chiperase:
call display_currentproc
ret
program:
call display_currentproc
ret
erase_program:
call display_currentproc
ret
erase_program_lock:
call display_currentproc
ret

display_currentproc:
movzx ebx,byte [mainmenu_choicepointer]
mov si, [menuelements_pointer_array+2*ebx]
call bwritestring
call breadkey
ret
    

its an interesting problem isn't it?
Post 02 Dec 2004, 02:37
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
i have found the source of the problem:
Grisoft AVG Executable/Heuristic checker hangs on for ~5 seconds while Flat assembler generating code, and also hangs on my menu code for a while upon executing, and for some reason, the version with macros is more suspicious? so hangs up more time.
Post 02 Dec 2004, 16:59
View user's profile Send private message Visit poster's website 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.