Assembly 使用stosb和lodsb hw加密解密nasm asm文件
几天来,我一直在尝试编写一个nasm asm文件,该文件使用stosb和lodsb获取用户输入,并使用“异或”对其进行有效加密,将其显示在屏幕上,然后解密并显示在屏幕上。我试图使用另一个asm文件,它做了类似的事情,并对其进行反向工程,但我无法通过用stosb加载字符串和用lodsb输出字符串。“打印到屏幕”部分是我试图打印使用stosb存储的内容的地方。在stosb和lodsb开始工作后,我还打算修改编码器解码部分。任何帮助都将不胜感激Assembly 使用stosb和lodsb hw加密解密nasm asm文件,assembly,encryption,nasm,x86-16,Assembly,Encryption,Nasm,X86 16,几天来,我一直在尝试编写一个nasm asm文件,该文件使用stosb和lodsb获取用户输入,并使用“异或”对其进行有效加密,将其显示在屏幕上,然后解密并显示在屏幕上。我试图使用另一个asm文件,它做了类似的事情,并对其进行反向工程,但我无法通过用stosb加载字符串和用lodsb输出字符串。“打印到屏幕”部分是我试图打印使用stosb存储的内容的地方。在stosb和lodsb开始工作后,我还打算修改编码器解码部分。任何帮助都将不胜感激 ; read a string ; en
; 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)
您必须将地址放入SI寄存器(而不是DX寄存器)。循环中不需要CLD。在循环之前执行一次。欢迎使用SO。我假设您正试图在DOS/Windows下执行此操作(因为您正在呼叫21h)。如果这是真的,您可以添加一些关于您正在使用的操作系统的更多信息吗?在Windows机器上使用nasm和dosbox(仿真器)。8086处理器
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