Вечером решил попробовать свои силы в программировании. Нашел готовый пример и стал писать код. Для первого раза получилось неплохо:
;2147483647=$7FFFFFFF
format PE64 GUI 5.0
entry start
include 'win64a.inc'
section '.text' code readable executable
start:
sub rsp,8*5
mov rbx,$7FFFFFFF
lea rsi,[MsgBoxText]
push rsi
mov rcx,10
lp:
mov rax,rbx
xor rdx,rdx
div rcx
mov rbx,rax
add rdx,$30
mov byte [ds:rsi],dl
inc rsi
or rbx,rbx
jne lp
mov byte [ds:rsi],0
dec rsi
;mirror text
pop rbx
mov rcx,rsi
sub rcx,rbx
shr rcx,1
or rcx,rcx
je print
mirror:
mov ah,byte [ds:rsi]
mov al,byte [ds:rbx]
mov byte [ds:rsi],al
mov byte [ds:rbx],ah
inc rbx
dec rsi
loop mirror
;output
print:
invoke MessageBox, NULL, MsgBoxText, MsgCaption, MB_OK
invoke ExitProcess, NULL
section '.data' data readable writeable
MsgCaption db "64bit to dec",0
MsgBoxText db "Win64 Assembly is Great!",0
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL'
format PE64 GUI 5.0
entry start
include 'win64a.inc'
section '.text' code readable executable
start:
sub rsp,8*5
mov rbx,$7FFFFFFF
lea rsi,[MsgBoxText]
push rsi
mov rcx,10
lp:
mov rax,rbx
xor rdx,rdx
div rcx
mov rbx,rax
add rdx,$30
mov byte [ds:rsi],dl
inc rsi
or rbx,rbx
jne lp
mov byte [ds:rsi],0
dec rsi
;mirror text
pop rbx
mov rcx,rsi
sub rcx,rbx
shr rcx,1
or rcx,rcx
je print
mirror:
mov ah,byte [ds:rsi]
mov al,byte [ds:rbx]
mov byte [ds:rsi],al
mov byte [ds:rbx],ah
inc rbx
dec rsi
loop mirror
;output
print:
invoke MessageBox, NULL, MsgBoxText, MsgCaption, MB_OK
invoke ExitProcess, NULL
section '.data' data readable writeable
MsgCaption db "64bit to dec",0
MsgBoxText db "Win64 Assembly is Great!",0
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL'
include 'api\kernel32.inc'
include 'api\user32.inc'
Дополнение. в коде нашлась одна ошибка. Улучшенный вариант.
Комментарии
Отправить комментарий