[程設雜筆] 初探MASM組合語言+課本習題練習

這學期選了一門組合語言,話不多說,直接上程式碼


Converting from big endian to little endian

[code]

TITLE ch4-1

include Irvine32.inc
include Macros.inc

.data
bigE BYTE 12h, 34h, 56h, 78h
littleE DWORD ?
little BYTE 0,0,0,0
.code
main PROC
mov ebx,0
mov ecx, 3
mov esi, offset bigE ;save bigE address
mov edi, offset little ;save little address

L1:
mov al, [esi+ebx]
mov [edi+ecx], al
dec ecx
inc ebx
cmp ebx, 4
jne L1

mov eax, DWORD PTR little ;mov little array into littleE
mov littleE,eax
mov eax,littleE
call WriteHex ;print
call ReadInt
exit
main ENDP
end main</pre>
<pre>[/code]

output:
12345678

copy a string in reverse order

[code]
TITLE ch4-1

include Irvine32.inc
include Macros.inc

.data
source BYTE "1234567890",0
target BYTE SIZEOF source DUP(‘ ‘)

.code
main PROC
mov esi,OFFSET source ;esi ptr of source
mov edi,esi ;edi initial place-1
mov ebp,OFFSET target ;ebp ptr of target
sub edi,1
add esi,SIZEOF source
sub esi,2
L1:
mov al,[esi]
call WriteChar
mov [ebp],al
dec esi ;esi 遞減
inc ebp ;ebp 遞增
call DumpRegs
cmp esi,edi
jne L1

mov edx,OFFSET source ;列印
call WriteString
mov al,0Ah
call WriteChar
mov edx,OFFSET target
call WriteString
call ReadInt
exit
main ENDP
end main
[/code]

output:
1234567890
0987654321

好累,第一次寫,寫三題寫了三個小時= =
寫C大概10分鐘就寫完了QAQ

參考資料:
http://blog.xuite.net/asd.wang/alog/269353-%5BMasm%5D+Assembly+%E7%AD%86%E8%A8%98+-+Ch5+%E7%A8%8B%E5%BA%8F

關於我:

我是沒一村,專長和興趣是程式、主動投資、科技商業模式。可以參考我的書單和比較熱門的文章:

分享:

Leave a Reply