Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 反向串MASM_Assembly_Masm_Irvine32_Masm32 - Fatal编程技术网

Assembly 反向串MASM

Assembly 反向串MASM,assembly,masm,irvine32,masm32,Assembly,Masm,Irvine32,Masm32,我设计了这段代码,在“originString”中获取一个字符串,并在“destinationString”中以相反的顺序放置它。我不知道如何让destinationString填充,而不是只保留一个值,然后用writeString而不是writeChar打印出来。这是我的 INCLUDE Irvine32.inc INCLUDELIB Irvine32.lib .386 .model flat, stdcall .stack 4096 ExitProcess PROTO, dwE

我设计了这段代码,在“originString”中获取一个字符串,并在“destinationString”中以相反的顺序放置它。我不知道如何让destinationString填充,而不是只保留一个值,然后用writeString而不是writeChar打印出来。这是我的

INCLUDE     Irvine32.inc
INCLUDELIB  Irvine32.lib

.386
.model flat, stdcall
.stack 4096

ExitProcess PROTO, dwExitCode:DWORD

.data
originString        BYTE    "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0
destinationString   BYTE    SIZEOF originString DUP(?), 0
counter             BYTE    1




.code
main PROC
    ; YOUR CODE GOES HERE...
    ; Write a procedure that copies the contents of 'originString' to
    ;  'destinationString', but in reverse order.  You should use the
    ;  provided initialization value for 'originString' to test, but your
    ;  solution must work even if the contents or 'originString' are changed.
    MOV EAX, LENGTHOF originString
    MOV ECX, EAX

countLoop_BEGIN:
                    
    MOVZX EAX, counter
    MOV EBX, LENGTHOF originString
    SUB EBX, EAX
    MOV AL, BYTE PTR [originString + (EBX-1)]
    cmp destinationString, ' '
    je   end_shifting
    inc EBX
    MOV destinationString, AL
    MOVZX EDX, destinationString
    CALL WriteString
    ;CALL Crlf
    INC counter

    LOOP countLoop_Begin    ; If ECX IS NOT EQUAL to 0, decrement ECX by 1 and JMP to 'countLoop_Begin'.
                            ; If ECX IS EQUAL to 0, do not jump and move onto the instruction following LOOP.

    MOV destinationString, AL
    MOV EDX, OFFSET destinationString
    CALL WriteString
    CALL Crlf
    end_shifting:    
        ret


    INVOKE ExitProcess, 0

main ENDP



END main
我不知道如何让命运之弦充满,而不是仅仅持有一个值

在循环中,指令
MOV destinationString,AL
始终写入destinationString的第一个位置。为什么不像从originString读取一样为write编制索引呢?您也可以使用计数器为写入内容编制索引

这是一个快速解决方案:

countLoop_BEGIN:
    MOVZX EDX, counter                  ; 1,2,3,...
    MOV   EBX, LENGTHOF originString
    SUB   EBX, EDX
    MOV   AL, [originString + (EBX-1)]
    MOV   [destinationString + (EDX-1)], AL
    INC   counter
    DEC   ECX
    JNZ   countLoop_Begin

然后用writeString打印出来,而不仅仅是writeChar

要使WriteString正常工作,您仍然需要将destinationString归零

    MOV   byte [destinationString + EDX], 0
    MOV   EDX, OFFSET destinationString
    CALL  WriteString