逆向程序 emu8086
Reverse Program emu8086
我需要编写一个颠倒字母顺序的程序。我编写了以下程序,但它对我不起作用。
请帮我修复我的程序:
org 100h
jmp main
string db 'm', 'g', 'g', 'i', 'h', 's', 'f', 'g', 'm',0Dh,0Ah,'$'
main:
lea ax,string
push 9
push offset string
call reverse
lea ax,string
mov ah,0
int 16h
ret
reverse proc
push bp
mov bp,sp
sub sp,6;
len equ [bp + 6]
i equ [bp - 4]
temp equ [bp - 2]
mov ax,[bp+6]
mov len,ax
dec len
mov dx,len
mov i,ax
mov bx,[bp+4]
mov ax,i
for1:
mov si,i
mov cl, [bx+si]
mov dl, cl
mov di, ax
sub di, si
mov [bx+di],cl
mov cl,dl
mov [bx+si], cl
mov ax,len
mov cl,2
div cl
dec i
cmp i,ax
jge for1
mov sp,bp
pop bp
ret
reverse endp</code>
................................................
乌里
你有一些不必要的代码,还有一些错误的代码。我做了一些更改以使其成为 运行,在这里(评论解释了更改),将其复制粘贴到 EMU8086 和 运行 上:
org 100h
jmp main
string db 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',0Dh,0Ah,'$'
i dw ? ;POINTER TO STRING FROM LEFT TO RIGHT.
j dw ? ;POINTER TO STRING FROM RIGHT TO LEFT.
len dw ? ;LEN IS BETTER HERE FOR DEBUGGING.
main:
lea ax,string
push 9
push offset string
call reverse
lea ax,string
mov ah,0
int 16h
ret
reverse proc
push bp
mov bp,sp
;sub sp,6; ;UNNECESSARY.
;len equ [bp + 6] ;UNNECESSARY.
;i equ [bp - 4] ;UNNECESSARY.
;temp equ [bp - 2] ;UNNECESSARY.
mov ax,[bp+6]
mov len,ax
;dec len ;UNNECESSARY.
;mov dx,len ;UNNECESSARY.
;mov i,ax ;UNNECESSARY.
;mov bx,[bp+4] ;UNNECESSARY.
;mov ax,i ;UNNECESSARY.
mov i, offset string ;I POINTS TO FIRST ELEMENT.
mov j, offset string ;J POINTS TO FIRST ELEMENT.
add j, ax ;J POINTS BEYOND LAST ELEMENT.
dec j ;J POINTS TO LAST ELEMENT.
shr len, 1 ;LEN / 2 (50% OF STRING WILL BE SWAPPED).
for1:
mov si,i ;SI POINTS TO FIRST ELEMENT.
mov di,j ;DI POINTS TO LAST ELEMENT.
mov cl,[si] ;CL = FIRST ELEMENT.
mov dl,[di] ;DL = LAST ELEMENT.
;mov di, ax
;sub di, si ;UNNECESSARY.
mov [si],dl ;LAST ELEMENT REPLACES FIRST.
;mov cl,dl ;UNNECESSARY.
mov [di], cl ;FIRST ELEMENT REPLACES LAST.
;mov ax,len ;UNNECESSARY.
;mov cl,2 ;UNNECESSARY.
;div cl ;UNNECESSARY.
;dec i ;UNNECESSARY.
;cmp i,ax ;UNNECESSARY.
inc i ;NEXT ELEMENT.
dec j ;PREVIOUS ELEMENT.
dec len ;(LEN/2)--.
cmp len, 0 ;IF ( LEN >= 0 ) ...
jge for1
;mov sp,bp ;UNNECESSARY.
pop bp
ret
reverse endp
我需要编写一个颠倒字母顺序的程序。我编写了以下程序,但它对我不起作用。
请帮我修复我的程序:
org 100h
jmp main
string db 'm', 'g', 'g', 'i', 'h', 's', 'f', 'g', 'm',0Dh,0Ah,'$'
main:
lea ax,string
push 9
push offset string
call reverse
lea ax,string
mov ah,0
int 16h
ret
reverse proc
push bp
mov bp,sp
sub sp,6;
len equ [bp + 6]
i equ [bp - 4]
temp equ [bp - 2]
mov ax,[bp+6]
mov len,ax
dec len
mov dx,len
mov i,ax
mov bx,[bp+4]
mov ax,i
for1:
mov si,i
mov cl, [bx+si]
mov dl, cl
mov di, ax
sub di, si
mov [bx+di],cl
mov cl,dl
mov [bx+si], cl
mov ax,len
mov cl,2
div cl
dec i
cmp i,ax
jge for1
mov sp,bp
pop bp
ret
reverse endp</code>
................................................ 乌里
你有一些不必要的代码,还有一些错误的代码。我做了一些更改以使其成为 运行,在这里(评论解释了更改),将其复制粘贴到 EMU8086 和 运行 上:
org 100h
jmp main
string db 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',0Dh,0Ah,'$'
i dw ? ;POINTER TO STRING FROM LEFT TO RIGHT.
j dw ? ;POINTER TO STRING FROM RIGHT TO LEFT.
len dw ? ;LEN IS BETTER HERE FOR DEBUGGING.
main:
lea ax,string
push 9
push offset string
call reverse
lea ax,string
mov ah,0
int 16h
ret
reverse proc
push bp
mov bp,sp
;sub sp,6; ;UNNECESSARY.
;len equ [bp + 6] ;UNNECESSARY.
;i equ [bp - 4] ;UNNECESSARY.
;temp equ [bp - 2] ;UNNECESSARY.
mov ax,[bp+6]
mov len,ax
;dec len ;UNNECESSARY.
;mov dx,len ;UNNECESSARY.
;mov i,ax ;UNNECESSARY.
;mov bx,[bp+4] ;UNNECESSARY.
;mov ax,i ;UNNECESSARY.
mov i, offset string ;I POINTS TO FIRST ELEMENT.
mov j, offset string ;J POINTS TO FIRST ELEMENT.
add j, ax ;J POINTS BEYOND LAST ELEMENT.
dec j ;J POINTS TO LAST ELEMENT.
shr len, 1 ;LEN / 2 (50% OF STRING WILL BE SWAPPED).
for1:
mov si,i ;SI POINTS TO FIRST ELEMENT.
mov di,j ;DI POINTS TO LAST ELEMENT.
mov cl,[si] ;CL = FIRST ELEMENT.
mov dl,[di] ;DL = LAST ELEMENT.
;mov di, ax
;sub di, si ;UNNECESSARY.
mov [si],dl ;LAST ELEMENT REPLACES FIRST.
;mov cl,dl ;UNNECESSARY.
mov [di], cl ;FIRST ELEMENT REPLACES LAST.
;mov ax,len ;UNNECESSARY.
;mov cl,2 ;UNNECESSARY.
;div cl ;UNNECESSARY.
;dec i ;UNNECESSARY.
;cmp i,ax ;UNNECESSARY.
inc i ;NEXT ELEMENT.
dec j ;PREVIOUS ELEMENT.
dec len ;(LEN/2)--.
cmp len, 0 ;IF ( LEN >= 0 ) ...
jge for1
;mov sp,bp ;UNNECESSARY.
pop bp
ret
reverse endp