1
.text
은 읽기 전용이므로 어셈블리에서 자체 수정 코드가 가능한지보고 싶었습니다. 대신 코드를 .data
에 넣을 수 있다고 생각했지만 아래 코드를 시도했습니다. 자체를 수정 한 후, 대신 증가 명령의 감소 지시를 가져야 때문에 I는 2
예상되지만이 어셈블리 코드가 자체적으로 수정하지 않는 이유
section .text
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
mov al,3
mov rbx,cont1 ;store label cont1 in rbx so we can continue there
mov cl,byte [dec_op] ;put the opcode of the dec instruction in cl
mov byte [code],cl ;replace the inc instruction with a dec instruction
jmp code ;run the modified code
cont1:
mov byte [dat1],al ;store away the changed value
add byte [dat1],0x30 ;turn the internal numeric value into an ascii digit
mov eax,4 ;system call number (sys_write)
mov ebx,1 ;stdout
mov ecx,dat1 ;location of data
mov edx,2 ;length of data
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
dat1 db 0,0xa ;location to store output
dec_op dec al ;the dec instruction
code inc al ;code to modify
jmp rbx
위의 출력
4
이다. 내가 도대체 뭘 잘못하고있는 겁니까?
내가 데비안 SID 64 비트를 실행하는거야 내가 컴파일 해요 :
nasm -f elf64 sm.s
ld -s -o sm sm.o
http://en.wikipedia.org/wiki/Self-modifying_code#Interaction_of_cache_and_self-modifying_code –
@HansPassant 그 의미가, 당신은 캐시를 syncronize하는 데 필요한 지침에 모든 자원을해야합니까? –
올바른 양식의 thje 자체 수정 코드를 수행하고 있습니다. 수정을 한 후에 jmp를 사용하면 프리 페치를 지우는 데 필요한 모든 작업을 수행 할 수 있습니다. – Jasen