程序集80x86中的嵌套循环-字符串问题

时间:2018-12-10 16:30:57

标签: assembly architecture x86 nested-loops ollydbg

大家好,节日快乐! 我遇到这个作业问题,说:A string of bytes 'input' is given together with two additional strings of N bytes each, 'src' and 'dst'. Obtain a new string of bytes called 'output' from the 'input' string, by replacing all the bytes with the value src[i] with the new value dst[i], for i=1..N.

例如:

input: 1,5,4,7,9,3,4,1,5 
src: 1,2,3,4
dst: 9,8,7,6
output: 9,5,6,7,9,7,6,9,5

我在这门课程上不是很出色,我正在努力提高!我已经考虑过使用嵌套循环来解决此问题(我想不出其他任何方式),并且提出了以下代码:(我会把它完整地表达出来,以便任何想要的人都可以尝试)

Bits 32 
global start
extern exit; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll; exit is a function that ends the calling process. It is defined in msvcrt.dll 
; our data is declared here (the variables needed by our program)
segment data use32 class=data
    input db 1,5,4,7,9,3,4,1,5 
    len equ $-input  ;size of inputs
    src db 1,2,3,4
    dst db 9,8,7,6
    n equ  4  ;size n of src and dst
    output db 0  ; output: 9,5,6,7,9,7,6,9,5
    count dd 0 ; I use this count to keep track of ECX for the loops
; our code starts here
segment code use32 class=code
    start:
    mov esi,input ;in esi we will store the FAR address of the string "input"
    cld ;parse the string from left to right(DF=0).    
    mov ecx,len ;we will parse the elements of the string in a loop with len iterations.
    repeat:
        mov count,[ecx]
        mov ecx,[n]
        mov edi,src ;in edi we will store the FAR address of the string "src"
        repeat2:
            cmpsb
            JE et:
                mov output,[esi]
            et:
                mov edx,[edi+4]
                mov output,[edx]
        loop repeat2
        mov ecx,count
    loop repeat



sfarsit:

        push dword 0; push the parameter for exit onto the stack
        call [exit]; call exit to terminate the program

该代码不起作用!汇编器给我这些错误: 操作码和操作数的无效组合 对于25、30、31和34行,它们是:

25.mov count,[ecx]
30.JE et:
31.mov output,[esi]
34.mov output,[edi]

这就是我现在得到的...

CPU Disasm
Address   Hex dump          Command                                  Comments
00402006      8B            DB 8B
00402007      0D            DB 0D                                    ; Carriage Return
00402008      09            DB 09                                    ; TAB
00402009      00            DB 00
0040200A      00            DB 00
0040200B      00            DB 00
0040200C      8A            DB 8A
0040200D      11            DB 11
0040200E      88            DB 88
0040200F      15            DB 15

0 个答案:

没有答案