汇编中如何判断二维数组的第二行是否降序排列

问题描述 投票:0回答:0

任务是:判断一个二维数组的第二行是否降序排列。我需要使用 assembly masm 来做到这一点。这是代码:

.686
.model flat, stdcall
option casemap:none

include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\masm32.inc
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib
includeLib C:\masm32\lib\masm32.lib

.data
    sConsoleTitle BYTE "Task", 0
    task BYTE "Check if the second row of a two-dimensional array is sorted in descending order", 0Dh, 0Ah, 0
    Arr     DWORD   4, 6, 2, 8
    RowSize = ($ - Arr)
            DWORD    9, 4, 2, 1
            DWORD    7, 3, 5, 1
            DWORD    6, 8, 1, 7
    resultText BYTE "Result: "
    row BYTE 4
    col BYTE 4
    i BYTE 0
    j BYTE 0
    exitText BYTE "Print enter to exit....", 0Dh, 0Ah, 0
    pos BYTE "Yes", 0Dh, 0Ah, 0
    negative BYTE "No", 0Dh, 0Ah, 0
    resultStr BYTE 16 DUP(' ')
    buffer BYTE 20 DUP(?), 0
    clrt BYTE 0Ah, 0Dh, 0
    tab BYTE "  ", 0
    sum DWORD 0

.code
start:
invoke SetConsoleTitle, offset sConsoleTitle
invoke StdOut, offset task

; Show array
xor ecx, ecx
mov cl, row
mov esi, 0
loop_row_1:
    push ecx
    xor ecx, ecx
    mov cl, col
    mov ebx, 0
loop_col_1:
    mov eax, Arr[esi][ebx]
    push ebx
    push ecx
    push esi
    invoke ltoa, eax, ADDR buffer
    invoke StdOut, ADDR buffer
    invoke StdOut, ADDR tab
    pop esi
    pop ecx
    pop ebx
    add ebx, TYPE Arr

    loop loop_col_1
    invoke StdOut, ADDR clrt

    add esi, RowSize

    pop ecx
    loop loop_row_1

; Check
mov esi,1
xor ecx, ecx
mov cl, col
mov ebx, 0
mov j, 0
loop_col_2:
    mov eax, Arr[esi][ebx]
    cmp eax, 0
    jle no
    add ebx, TYPE Arr
    loop loop_col_2
    invoke StdOut, ADDR clrt
yes:
    invoke StdOut, ADDR resultText
    invoke StdOut, ADDR pos
    jmp exit
no:
    invoke StdOut, ADDR resultText
    invoke StdOut, ADDR negative
exit:
    invoke StdIn, ADDR buffer, lengthof buffer
end start

为什么我总是得到肯定的答案,顺便说一句,当我将 esi 寄存器的值更改为另一个值时(该寄存器负责检查哪个字符串),我总是得到它。我不知道我做错了什么。 (实际上,也许我用寄存器做了一些事情,但我有一个与我的任务几乎相同的例子,我写了这个例子中的代码,但问题仍然存在)

assembly masm
© www.soinside.com 2019 - 2024. All rights reserved.