2007-10-27

2007-10-22

【X86組語】作業二-第二版

;;修正第二運算元,第二運算元如果只有一位元,可以選擇按enter鍵即進行運算。
;;前一版請參考http://new-acos.blogspot.com/2007/10/x86_21.html
GETCHAR MACRO char
push ax
mov ah,01h
int 21h
mov char,al
pop ax
ENDM
PUTCHAR MACRO char
push dx
push ax
mov dl,char


mov ah,02h
int 21h
pop ax
pop dx
ENDM
END_PROCESS MACRO
mov ah,4ch
int 21h
ENDM

.MODEL SMALL
.DATA
values db 2 dup(?)
operator db 1 dup(?)
answer db 1 dup(?)

.STACK

.CODE
main_pro proc far


mov dl,3
count_loop: mov si,0
keyin_loop: GETCHAR bl
cmp bl,'+'
je go_1
cmp bl,'-'
jne continue
go_1: cmp si,0
je invalid
mov [operator],bl
jmp keyin_loop
go_2: mov [operator],bl
jmp finish

continue: call check_num
mov cl,bl
GETCHAR bl
cmp bl,'+'
je go_2
cmp bl,'-'
je go_2
cmp bl,0dh
je finish
mov al,10
mul cl
mov cl,al
call check_num
add cl,bl
finish: mov [values+si],cl
inc si
cmp si,2
jne keyin_loop

mov al,[values]
mov bl,[values+1]
mov cl,[operator]
cmp cl,'-'

jne do_add
sub al,bl
mov [answer],al
call print_ans
jmp ok
do_add: add al,bl
mov [answer],al
call print_ans
ok: dec dl
jnz count_loop

END_PROCESS
main_pro endp

check_num proc far
cmp bl,'0'

jl invalid
cmp bl,'9'
jg invalid
sub bl,'0'

ret
check_num endp

print_ans proc far
call cr
xor ax,ax
mov al,[values]
call print_num
PUTCHAR [operator]
xor ax,ax
mov al,[values+1]
call print_num
PUTCHAR '='
xor ax,ax
mov al,[answer]
call print_num
call lf
ret
print_ans endp

print_num proc far
push cx
mov ch,1
cmp al,100
jb ignore_h
xor ch,ch
PUTCHAR '1'
sub al,100
ignore_h: mov cl,10
div cl
cmp al,0
jne go_3
cmp ch,0
jne go_4
go_3: add al,'0'

PUTCHAR al
go_4: add ah,'0'
PUTCHAR ah
pop cx
ret
print_num endp

cr proc near
push ax
push dx
mov ah,2
mov dl,0dh
int 21h
pop dx
pop ax
ret
cr endp

lf proc far
push ax
push dx
call cr
mov ah,2
mov dl,0ah
int 21h
pop dx
pop ax
ret
lf endp


invalid: PUTCHAR '!'
END_PROCESS
END

2007-10-21

【X86組語】作業二

作業二,0~99兩數字加減法


;;;; 程式說明 ;;;;
;; 使用者輸入一算數
GETCHAR MACRO char
push ax
mov ah,01h
int 21h
mov char,al
pop ax
ENDM
PUTCHAR MACRO char
push dx
push ax
mov dl,char

mov ah,02h
int 21h
pop ax
pop dx
ENDM
END_PROCESS MACRO
mov ah,4ch
int 21h
ENDM

.MODEL SMALL
.DATA
values db 2 dup(?)

operator db 1 dup(?)

.STACK

.CODE
main_pro proc far

mov dl,3
count_loop: mov si,0
keyin_loop: GETCHAR bl
cmp bl,'+'

je go_1
cmp bl,'-'
jne continue
go_1: cmp si,0
je invalid
mov [operator],bl
jmp keyin_loop
go_2: mov [operator],bl
jmp finish
continue: call check_num
mov cl,bl
GETCHAR bl
cmp bl,'+'

je go_2
cmp bl,'-'
je go_2
mov al,10
mul cl
mov cl,al
call check_num
add cl,bl
finish: mov [values+si],cl
inc si
cmp si,2
jne keyin_loop

mov al,[values]
mov bl,[values+1]
mov cl,[operator]
cmp cl,'-'
jne do_add
sub al,bl
call print_ans
jmp ok
do_add: add al,bl
call print_ans
ok: dec dl
jnz count_loop

END_PROCESS
main_pro endp



check_num proc far
cmp bl,'0'

jl invalid
cmp bl,'9'
jg invalid
sub bl,'0'
ret
check_num endp

print_ans proc far
PUTCHAR '='
cmp al,100
jb ignore_h
PUTCHAR '1'

sub al,100
ignore_h: mov cl,10
div cl
add al,'0'
add ah,'0'
PUTCHAR al
PUTCHAR ah
call cr_lf
ret
print_ans endp


cr_lf proc far
push ax
push dx
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
pop ax
ret
cr_lf endp


invalid: PUTCHAR '!'
END_PROCESS
END

2007-10-15

【X86組語】作業一

作業一
說明:
  使用者每次輸入五個數值(五張撲克牌),若輸入錯誤牌值或是輸入'!'字元程式結束。
  程式不印中獎名稱,改印中獎編號。
PS. 僅接受01~0d, 11~1d, 21~2d, 31~3d(限小寫)

GETCHAR     MACRO   char
mov ah,01h
int 21h
mov char,al
ENDM
PUTCHAR MACRO char
mov ah,02h
mov dl,char
int 21h
ENDM
END_PROCESS MACRO
mov ah,4ch
int 21h
ENDM


.MODEL SMALL
.DATA
abc equ 61
cde equ 55
key_temp db 2 dup(?)
card_5 db 5 dup(?)
temp_5 db 5 dup(?)
max_prize db ?
max_num db ?
ceq db ?
prize db ?
_mask db 00001000b,00000100b,00000010b,00000001b
pr_tab db 0,1,1,3,1,2,3,7,1,2,2,6,3,6,7,10
card_tab db 1,2,3,4,5, 1,2,3,4,6, 1,2,3,5,6
db 1,2,4,5,6, 1,3,4,5,6, 2,3,4,5,6
db 1,2,3,4,7, 1,2,3,5,7, 1,2,4,5,7
db 1,3,4,5,7, 2,3,4,5,7, 1,2,3,6,7
db 1,2,4,6,7, 1,3,4,6,7, 2,3,4,6,7
db 1,2,5,6,7, 1,3,5,6,7, 2,3,5,6,7
db 1,4,5,6,7, 2,4,5,6,7, 3,4,5,6,7
card_52 db 01h,02h,03h,04h,05h,06h,07h
db 08h,09h,0ah,0bh,0ch,0dh
db 11h,12h,13h,14h,15h,16h,17h
db 18h,19h,1ah,1bh,1ch,1dh
db 21h,22h,23h,24h,25h,26h,27h
db 28h,29h,2ah,2bh,2ch,2dh
db 31h,32h,33h,34h,35h,36h,37h
db 38h,39h,3ah,3bh,3ch,3dh
mess db '** sorry !! ** $'
db ' ===> 1 $'
db ' ===> 2 $'
db ' ===> 3 $'

db ' ===> 4 $'
db ' ===> 5 $'
db ' ===> 6 $'

db ' ===> 7 $'
db ' ===> 8 $'
db ' ===> 9 $'

db 07h, ' %% error %% $'
;----------------------------------------------------------
.STACK 1000h
.CODE
main proc far
;
mov ax,@data
mov ds,ax

continue: mov di,5
key_round: GETCHAR [key_temp]
cmp [key_temp], '!'
je exit
GETCHAR [key_temp+1]
cmp [key_temp+1], '!'
je exit
PUTCHAR ' '

call transform
dec di
xor di,0
jne key_round
call check_5
;
call far ptr p_result
;
jmp continue

exit: END_PROCESS
main endp
;

transform proc
mov si,2
trans_run: mov ch,[key_temp-1+si]
cmp ch,'0'
jl err
cmp ch,'9'
jle is_num
cmp ch,'a'

jl err
cmp ch,'f'
jg err
sub ch,87
jmp go_f
is_num: sub ch,'0'
go_f: mov [key_temp-1+si],ch
dec si
xor si,0
jnz trans_run
;
mov cl,[key_temp]
mov al,16
mul cl
mov cl,[key_temp+1]
add al,cl
mov [card_5+di-1],al
ret
transform endp

err: PUTCHAR 'E'
PUTCHAR 'R'

PUTCHAR 'R'
PUTCHAR 'O'
PUTCHAR 'R'
PUTCHAR '!'
PUTCHAR '!'

END_PROCESS
;-----------------------------------------------------------------
check_5 proc near
mov [prize],0
mov ah,0fh
call copypure
call sorttemp_5
call compare
cmp [ceq],0
jne setprize

call checkstr

mov ah,30h
call copypure
call compare

cmp [ceq],0fh
jne noflush
cmp1: cmp bh,0
jne cmp2
mov [prize],5
jmp checkexit
cmp2: cmp bh,1
jne cmp3
mov [prize],8
jmp checkexit
cmp3: mov [prize],9
jmp checkexit

noflush: cmp bh,0
je nostraight
mov [prize],4
jmp checkexit

nostraight: mov [ceq],0

setprize: lea bx,pr_tab
mov al,[ceq]
xlat
mov [prize],al


checkexit: ret
check_5 endp
;---------------------------------------------------------------
copypure proc
mov si,5
pureloop: dec si
mov al,[card_5 + si]
and al,ah
mov [temp_5 + si],al
cmp si,0
jne pureloop
ret
copypure endp
;--------------------------------------------------------------
sorttemp_5 proc near
mov si,4
sortloop1: mov al,[ temp_5 + si ]
mov di,0
sortloop2: cmp al,[ temp_5 + di ]
jge sortnext
xchg al,[ temp_5 +di ]
sortnext: inc di
cmp di,si
jne sortloop2
mov [ temp_5 + si ],al
dec si
jnz sortloop1

ret
sorttemp_5 endp
;--------------------------------------------------------------
compare proc
mov [ceq],0
mov si,0

cmploop: mov ah,[temp_5 + si]
xor ah,[temp_5 + si + 1]
jnz cmpnext
mov al,[_mask + si]
or [ceq],al
cmpnext: inc si
cmp si,4
jnz cmploop
ret
compare endp
;--------------------------------------------------------------
checkstr proc near
mov bh,0
mov al,[temp_5 +4]
sub al,[temp_5 +0]
cmp al,4
je addbh
cmp al,12
jne strexit

mov al,[temp_5+1]
cmp al,10
jne strexit
inc bh
addbh: inc bh
strexit: ret
checkstr endp
;----------------------------------------------------
p_result proc far
mov bl,[prize]
mov al,16
mul bl
lea dx,mess
add dx,ax
mov ah,09h
int 21h
cmp bl,0
ret
p_result endp
END main

【X86組語】上課用講義內容

徐泓洋老師上課教學用的程式碼。
功能說明:程式每次執行會自動抓取亂數設定牌值與花色,並且依照亂數產生的牌判斷得到的是one pair、two pair...等獎項或是槓龜...


.MODEL SMALL
.DATA
abc equ 61
cde equ 55

card_7 db 7 dup(?)
card_5 db 5 dup(?)
temp_5 db 5 dup(?)
max_prize db ?
max_num db ?
ceq db ?
prize db ?
_mask db 00001000b,00000100b,00000010b,00000001b
pr_tab db 0,1,1,3,1,2,3,7,1,2,2,6,3,6,7,10
card_tab db 1,2,3,4,5, 1,2,3,4,6, 1,2,3,5,6
db 1,2,4,5,6, 1,3,4,5,6, 2,3,4,5,6
db 1,2,3,4,7, 1,2,3,5,7, 1,2,4,5,7
db 1,3,4,5,7, 2,3,4,5,7, 1,2,3,6,7
db 1,2,4,6,7, 1,3,4,6,7, 2,3,4,6,7
db 1,2,5,6,7, 1,3,5,6,7, 2,3,5,6,7
db 1,4,5,6,7, 2,4,5,6,7, 3,4,5,6,7
card_52 db 01h,02h,03h,04h,05h,06h,07h
db 08h,09h,0ah,0bh,0ch,0dh
db 11h,12h,13h,14h,15h,16h,17h
db 18h,19h,1ah,1bh,1ch,1dh
db 21h,22h,23h,24h,25h,26h,27h
db 28h,29h,2ah,2bh,2ch,2dh
db 31h,32h,33h,34h,35h,36h,37h
db 38h,39h,3ah,3bh,3ch,3dh
mess db ' ** sorry !!! ** $'
db 'one pair $'
db 'two pairs $'
db 'three of a kind $'

db 'straight $'
db 'flush $'
db 'full house $'
db 'four of a kind $'
db 'flush straight $'

db 'flush royal $'
db 07h, '%% data error %% $'
;----------------------------------------------------------
.STACK 1000h
.CODE
main proc far
;
mov ax,@data
mov ds,ax
;
call far ptr cdgen
;
call far ptr check_7
;
call far ptr p_result
;
mov ah,4ch
int 21h
main endp
;
;----------------------------------------------------------
;
check_7 proc far
;
mov [max_prize],0
mov [max_num],0
;
mov cx,21
ckloop1: mov al,05h
mov dl,cl
dec dl
mul dl
mov bx,ax
mov si,5
ckloop2: dec si
mov al,[card_tab + bx + si]
mov di,ax
mov al,[card_7 - 1 + di]
mov [card_5 + si],al
xor si,0
jnz ckloop2
;
call check_5
;
mov ah,[prize]
cmp ah,[max_prize]
jbe nextturn
;
mov [max_prize],ah
mov [max_num],cl
nextturn: loop ckloop1
ret
check_7 endp
;-----------------------------------------------------------------
check_5 proc near
mov [prize],0
mov ah,0fh
call copypure
call sorttemp_5
call compare
cmp [ceq],0
jne setprize

call checkstr

mov ah,30h
call copypure
call compare


cmp [ceq],0fh
jne noflush
cmp1: cmp bh,0
jne cmp2
mov [prize],5
jmp checkexit
cmp2: cmp bh,1
jne cmp3
mov [prize],8
jmp checkexit
cmp3: mov [prize],9
jmp checkexit

noflush: cmp bh,0
je nostraight
mov [prize],4
jmp checkexit

nostraight: mov [ceq],0

setprize: lea bx,pr_tab
mov al,[ceq]
xlat
mov [prize],al

checkexit: ret
check_5 endp
;---------------------------------------------------------------
copypure proc
mov si,5
pureloop: dec si
mov al,[card_5 + si]
and al,ah
mov [temp_5 + si],al
cmp si,0
jne pureloop
ret
copypure endp
;--------------------------------------------------------------
sorttemp_5 proc near
mov si,4
sortloop1: mov al,[ temp_5 + si ]
mov di,0
sortloop2: cmp al,[ temp_5 + di ]
jge sortnext
xchg al,[ temp_5 +di ]
sortnext: inc di
cmp di,si
jne sortloop2
mov [ temp_5 + si ],al
dec si
jnz sortloop1

ret
sorttemp_5 endp
;--------------------------------------------------------------
compare proc
mov [ceq],0
mov si,0

cmploop: mov ah,[temp_5 + si]
xor ah,[temp_5 + si + 1]
jnz cmpnext
mov al,[_mask + si]
or [ceq],al
cmpnext: inc si ;74
cmp si,4
jnz cmploop
ret
compare endp
;--------------------------------------------------------------
checkstr proc near
mov bh,0
mov al,[temp_5 +4]
sub al,[temp_5 +0]
cmp al,4
je addbh
cmp al,12
jne strexit
cmp [temp_5 + si],10
jne strexit
cmp [temp_5 + si],10
jne strexit
inc bh
addbh: inc bh
strexit: ret
checkstr endp
;----------------------------------------------------
p_result proc far
mov bl,[max_prize]
mov al,20
mul bl
lea dx,mess
add dx,ax
mov ah,09h
int 21h
cmp bl,0
je pr_exit


mov bl,[max_num]
dec bl
mov al,05h
mul bl
mov bx,ax
mov ah,02h
mov dl,[card_tab + bx + 0]
or dl,30h
int 21h

mov si,1
prloop: mov dl,","
int 21h
mov dl,[card_tab + bx + si]
or dl,30h
inc si
cmp si,5
jne prloop
pr_exit: ret
p_result endp
;----------------------------------------------------
cdgen proc far

call randomize


mov cx,7
mov dh,52
rndloop: call random
lea bx,card_52
xor ah,ah
add bx,ax
mov ah,[bx]
mov si,cx
mov [card_7 - 1 + si],ah
xchg ah,[card_52 + 44 + si]
mov [bx],ah
dec dh
loop rndloop
ret
cdgen endp
;----------------------------------------------------
randomize proc near
mov ah,2ch
int 21h
shl dh,1
add dl,dh
ret
randomize endp
;----------------------------------------------------
random proc near

mov al,abc
mul dl
add ax,cde
mov dl,al
mul dh
mov al,ah
ret
random endp
END main

2007-10-09

【Ubuntu】7.10光碟開始提供索取申請

  這幾天讓人很興奮的是Ubuntu 7.10終於要釋出了!今天已經進入倒數九天了,從倒數十一天起就一直跑去Ubuntu官網晃,關注了兩天終於開放申請索取7.10的光碟,身為Ubuntu的忠實愛好者,當然也要趕緊來參一腳。這次申請選項少了一點,預設的光碟索取組合變得比較『不浪費』,這次預設選項最多2張光碟片,可以選擇兩張PC版的或是選擇PC、64bit版各一張。
  有興趣的使用者也可已到https://shipit.ubuntu.com/申請,如果需要地址翻譯的話可以參考台灣郵政網頁提供的轉換服務

2007-10-03

【X86組語】大小寫轉換

題目說明:
  等待使用者輸入字母('a'~'z'與'A'~'Z'),並做大小寫轉換。如果使用者輸入小寫字母,則螢幕印出對應的大寫字母,反之印出對應小寫字母,若輸入字母以外的字元則結束程式。

程式流程:

程式碼:

GETCHAR  MACRO
mov ah, 01h
int 21h
ENDM
PUTCHAR MACRO
mov ah, 02h
int 21h
ENDM
END_PROCESS MACRO
mov ah, 4ch
int 21h
ENDM

.MODEL SMALL
.CODE
begin: GETCHAR
cmp al, 'A'
jl exit
cmp al, 'Z'

jle upper
cmp al, 'a'
jl exit
cmp al, 'z'
jg exit
sub al, 20h
mov dl, al
PUTCHAR
jmp begin
upper: add al, 20h
mov dl, al
PUTCHAR
jmp begin
exit: END_PROCESS
.STACK
END begin

程式說明:
  輸入輸出巨集請參考課本程式5-0,程式流程從begin標籤開始。

2007-10-01

i-city 網路城市

滿特別的網站,內容是介紹逢甲附近商圈的店家,有地圖、論壇提供消費分享資訊。
位址:http://www.i-city.com.tw/