Мы все привыкли к определённому синтаксису ассемблера, который придуман не нами и имеет вполне конкретную историю происхождения.
Давайте на секунду представим, что мы можем поменять синтаксис не меняя сути.
Вот моя небольшая фантазия на эту тему.
Возьмем, к примеру, небольшой фрагмент кода из КолибриОС:
Code: Select all
NoteforOctave:
sub al, 0x81 ; correction value for delay Note
mov [countDelayNote], al; save counter delay this new Note
call ReadNoteByte
cmp al, 0xFF ; this is PAUSE ?
jne packCode ; no, this is PACK CODE
in al, 0x61 ; Get contents of system port B chip 8255
and al, 0xFC ; Turn OFF timer and speaker
out 0x61, al ; Send out new values to port B chip 8255
jmp saveESI
packCode:
mov cl, al ; save code
and al, 0xF ; clear upper bits
dec al ; correction
add al, al ; transform number to offset constant
movsx eax, al ; EAX - offset
add eax, dword kontrOctave; EAX - address from constant
mov ax, [eax] ; read constant
shr cl, 4 ; transform for number Octave
shr ax, cl ; calculate from Note this Octave!
pokeNote:
out 0x42, al ; Lower byte Out to channel 2 timer chip 8253
mov al, ah
out 0x42, al ; Upper byte Out to channel 2 timer chip 8253
in al, 0x61 ; Get contents of system port B chip 8255
or al, 3 ; Turn ON timer and speaker
out 0x61, al ; Send out new values to port B chip 8255
saveESI:
pop eax
RET
ReadNoteByte:
;result:
; al - note
push eax
push ecx
push edx
push esi
mov eax, [pidProcessNote]
call pid_to_slot
test eax, eax
jz .failed
lea ecx, [esp+12]
mov edx, 1
mov esi, [memAdrNote]
inc [memAdrNote]
call read_process_memory
.failed:
pop esi
pop edx
pop ecx
pop eax
ret
Code: Select all
NoteforOctave:
al - 0x81 ; correction value for delay Note
[countDelayNote] = al ; save counter delay this new Note
ReadNoteByte()
al <> 0xFF: packCode ; this is PAUSE ? ; no, this is PACK CODE
0x61 -> al ; Get contents of system port B chip 8255
al & 0xFC ; Turn OFF timer and speaker
0x61 <- al ; Send out new values to port B chip 8255
jmp saveESI
packCode:
cl = al ; save code
al & 0xF ; clear upper bits
-- al ; correction
al + al ; transform number to offset constant
movsx eax, al ; EAX - offset
eax + dword kontrOctave; EAX - address from constant
ax = [eax] ; read constant
cl >> 4 ; transform for number Octave
ax >> cl ; calculate from Note this Octave!
pokeNote:
0x42 <- al ; Lower byte Out to channel 2 timer chip 8253
al = ah
0x42 <- al ; Upper byte Out to channel 2 timer chip 8253
0x61 -> al ; Get contents of system port B chip 8255
al & 3 ; Turn ON timer and speaker
0x61 <- al ; Send out new values to port B chip 8255
saveESI:
pop eax
RET
ReadNoteByte:
;result:
; al - note
push eax, ecx, edx, esi
eax = [pidProcessNote]
pid_to_slot()
eax && eax
jz .failed
ecx =^ [esp+12]
edx = 1
esi = [memAdrNote]
++ [memAdrNote]
read_process_memory()
.failed:
pop esi, edx, ecx, eax
RET
Как вы относитесь к подобной идее?