創作內容

5 GP

count letter (Assembly language X86)

作者:Breguet│2014-01-13 19:10:04│巴幣:10│人氣:518
題目要求:輸入一個字串,輸出英文字母的排列。
例:
input:I trust your judgement
output:degIjmnorrstttuuuy

解題觀念:
利用ASCII的觀念(A=65,a=97),利用bubble sort來排序,space為20h,也就是32,
先將小寫英文排完,在排開頭的大寫英文,即達成目標。





source code

TITLE Count Character Template (charCount.asm)
INCLUDE Irvine32.inc
.data
buffer BYTE 100 DUP(0)
message BYTE "Please enter a string:",0
sortBYTE "Sort :",0
.code
main PROC
call countLetter
exit
main ENDP
;----------------------------------------------------------------------------------------------------------
countLetter PROC
; bubble sort with ASCII
;----------------------------------------------------------------------------------------------------------
mov edx,OFFSET message
call writeString
mov edx,OFFSET buffer
mov ecx,SIZEOF buffer
call ReadString

mov ecx,SIZEOF buffer
dec ecx
L1:
push ecx
mov edx,OFFSET buffer
mov ecx,SIZEOF buffer
dec ecx
L2:
mov al,[edx]
mov bl,[edx+1]
.IF al==0h || bl==0h
JMP J1
.ENDIF
.IF al>bl && bl!=20h;shift sapce==20h
mov [edx],bl
mov [edx+1],al
.ELSEIF al<=bl && al==20h;shift space==20h
mov [edx],bl
mov [edx+1],al
.ENDIF
add edx,1
loop L2
J1:
pop ecx
loop L1

mov edx,OFFSET buffer
mov esi,OFFSET buffer
add esi,1
mov al,[edx]
add al,32
mov ecx,-1
F1:
mov bl,[esi]
.IF al>bl
mov [esi-1],bl
add esi,1
.ELSEIF al<=bl
sub al,32
mov [esi-1],al
JMP E1
.ENDIF
JMP F1
E1:
mov edx,OFFSET sort
call writeString
mov edx,OFFSET buffer
call writeString
call crlf
call countLetter
ret
countLetter ENDP
END main




引用網址:https://home.gamer.com.tw/TrackBack.php?sn=2308484
All rights reserved. 版權所有,保留一切權利

相關創作

同標籤作品搜尋:Assembly language X86|bubble sort|letter

留言共 0 篇留言

我要留言提醒:您尚未登入,請先登入再留言

5喜歡★NTUCSIE 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:Binary Searc... 後一篇:Remove the S...

追蹤私訊切換新版閱覽

作品資料夾

aaa1357932大家
各位有空可以來我家看看畫作或聽聽我的全創作專輯!看更多我要大聲說昨天07:52


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】