我一直在尝试编写一个nasm asm文件,该文件使用stosb和lodsb来获取用户输入并使用“exclusive or”来有效加密它在屏幕上显示它然后解密并在屏幕上显示它。我试图使用另一个做类似的asm文件并对其进行逆向工程,但我无法通过stosb加载字符串并输出带有lodsb的字符串。打印到屏幕部分是我试图打印使用stosb存储的内容的地方。在让stosb和lodsb工作之后,我还要修改编码器解码部分。任何帮助将不胜感激。
; read a string
; encrypt it, and decrypt it.
org 100h
section .data
;___________________________DATA
prompt1: db "What is your secret message? $"
prompt2: db "The encrypted message is: $"
prompt3: db "The message after decryption is: $"
testout: db "*************** $"
key db 0Fh ; encryption key*
CRLF db 13, 10, '$' ; carriage return line feed
NULL db 0 ; null character
section .bss ; bss section*
buffer resb 80 ; 80 reserve bytes*
section .text
;_____________________________SCREEN TEXT
mov ah, 9 ; Used to print text stored in prompt1
mov dx, prompt1 ;
int 21h ; end text output
;_______________________INSTRING (KEYBOARD INPUT)
instring:
mov cx, 0 ; CX counts characters starts at 0
cld ; process string left to right*
mov di, buffer ; move buffer into data index*
mov ah, 1 ; read character from standard input*
int 21h ; read character*
while1: cmp al, 13 ; is character carriage return*
je endwhile1 ; if carriage return exit loop*
inc cx ; increment cx*
stosb ; store character just read into buffer*
int 21h ; read next character*
jmp while1 ; loop until all characters read*
endwhile1: ; endwhile1 (end of loop)*
mov byte [di], NULL ; store ASCII null character (end of array)*
mov dx, buffer ; dx is the address arg to print*?
;__________________________PRINT TO SCREEN
lp:
cld ; process string left to right*
lodsb
mov dl, al
mov ah, 2
int 21h
loop lp
;___________________________CODER (encode data)
; mov si,0 ; string index register(si = string index)***
;while1:
; cmp byte [si+msg],'$' ; looks for "$" to end loop***
; je endwhile1 ; "$" ends loop***
; mov al,[si+msg] ; moving through msg one character at a time***
; xor al,[key] ; XOR value stored in al (encode)***
; mov [si+coded],al ; move encoded character to al***
; inc si ; increment si (array index counter)***
; jmp while1 ;
;endwhile1:
;
; mov byte [si+coded],'$'
;
; mov ah,9 ; write string to standard output ***
; mov dx,coded ; store coded in output register ***
; int 21h ; output coded ***
;
;
;___DECODE SECTION
; mov si,0
;while2:
; cmp byte [si+coded],'$'
; je endwhile2
; mov al,[si+coded]
; xor al,[key]
; mov [si+decoded],al
; inc si
; jmp while2
;endwhile2:
;
; mov byte [si+decoded],'$'
;
;___DECODED SCREEN OUTPUT
; mov ah,2 ; write characer to standard output***
; mov dl,13 ; store carrage carriage return code***
; int 21h ; output carriage return***
; mov dl,10 ; line feed code***
; int 21h ; output line feed***
;
;
; mov ah,9 ; write string to standard output ***
; mov dx,decoded ; store decoded in output register ***
; int 21h ; output decoded ***
;
exit:
mov ah, 04Ch ; DOS function: Exit program
mov al, 0 ; Returns exit code value
int 21h ; Call DOS (Terminate Program)
答案 0 :(得分:2)
mov dx, buffer ; dx is the address arg to print*?
;__________________________PRINT TO SCREEN
lp:
cld ; process string left to right*
lodsb
mov dl, al
mov ah, 2
int 21h
loop lp
您必须将地址放在SI寄存器中(不在DX寄存器中) 循环中不需要CLD。在循环之前做一次。