Asm 測試 code block

日期: 分類: «組合語言» 作者: ols3

測試組合語言 code block:

.386
.model flat, stdcall
option casemap : none

.data
abc db "abc",0
def db "def",0

.code
start:

mov ecx,3     ;the length of the abc and def strings
cld           ;set the direction flag so that EDI and ESI will increase using repe
mov esi, offset [abc]  ;moves address of abc string into esi
mov edi, offset [def]  ;exact syntax may differ depending on assembler you use
                       ;I am not exactly sure what MASM accepts but certainly something similar to this
repe cmpsb     ;repeat compare [esi] with [edi] until ecx!=0 and current chars in strings match
               ;edi and esi increase for each repetition, so pointing to the next char
cmp ecx,0      ;test if the above command passed until the end of strings
je strings_are_equal  ;if yes then strings are equal
;here print the message that strings are not equal (i.e. invoke MessageBox)
jmp endcmp
strings_are_equal:
;here print the message that strings are equal (i.e. invoke MessageBox)
mov eax,10
endcmp:

xor eax, eax
    ret
end start