flat assembler
Message board for the users of flat assembler.

Index > Main > Execution of HEX input, optimization

Author
Thread Post new topic Reply to topic
xidevel



Joined: 14 Jan 2013
Posts: 2
xidevel 23 Jan 2013, 19:58
A program of 99 bytes:
Code:
00000000  6800B8            push word 0xb800
00000003  07                pop es
00000004  680000            push word 0x0
00000007  1F                pop ds
00000008  31FF              xor di,di
0000000A  31DB              xor bx,bx
0000000C  31C0              xor ax,ax
0000000E  CD16              int 0x16
00000010  B400              mov ah,0x0
00000012  2C30              sub al,0x30
00000014  91                xchg ax,cx
00000015  51                push cx
00000016  B90300            mov cx,0x3
00000019  81F90200          cmp cx,0x2
0000001D  7411              jz 0x30
0000001F  31C0              xor ax,ax
00000021  CD16              int 0x16
00000023  268807            mov [es:bx],al
00000026  43                inc bx
00000027  43                inc bx
00000028  81F90100          cmp cx,0x1
0000002C  7406              jz 0x34
0000002E  E2E9              loop 0x19
00000030  8BD0              mov dx,ax
00000032  E2E5              loop 0x19
00000034  80F841            cmp al,0x41
00000037  7D02              jnl 0x3b
00000039  7C05              jl 0x40
0000003B  80E837            sub al,0x37
0000003E  EB03              jmp short 0x43
00000040  80E830            sub al,0x30
00000043  80FA41            cmp dl,0x41
00000046  7D02              jnl 0x4a
00000048  7C05              jl 0x4f
0000004A  80EA37            sub dl,0x37
0000004D  EB03              jmp short 0x52
0000004F  80EA30            sub dl,0x30
00000052  C0E204            shl dl,byte 0x4
00000055  00D0              add al,dl
00000057  8805              mov [di],al
00000059  47                inc di
0000005A  59                pop cx
0000005B  E2B8              loop 0x15
0000005D  3EEA00000000      ds jmp word 0x0:0x0    

Wasteful 2-times pass:
Code:
cmp al,0x41
jnl 0x3b
jl 0x40
sub al,0x37
jmp short 0x43
sub al,0x30
    

I have clumsy loops, especially in this part:
Code:
00000016  B90300            mov cx,0x3
00000019  81F90200          cmp cx,0x2
0000001D  7411              jz 0x30
0000001F  31C0              xor ax,ax
00000021  CD16              int 0x16
00000023  268807            mov [es:bx],al
00000026  43                inc bx
00000027  43                inc bx
00000028  81F90100          cmp cx,0x1
0000002C  7406              jz 0x34
0000002E  E2E9              loop 0x19
00000030  8BD0              mov dx,ax
00000032  E2E5              loop 0x19
00000034  ...    
end
And no idea. And the converting algorithm works twice (with 2 JMPs). But the program works!
1 - enter quantity of bytes
2 - then enter those bytes
Code:
For example:
5
EA0000FFFF
reboot    
Smile


Last edited by xidevel on 24 Jan 2013, 14:06; edited 3 times in total
Post 23 Jan 2013, 19:58
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 509
Location: Czech republic, Slovak republic
Feryno 24 Jan 2013, 12:06
Hi, I remebered that years ago I read about something similar:
Programming in extreme conditions
by Kalmykov.b52
www.google.com/#hl=&tbo=d&q="Programming+in+extreme+conditions"+"Kalmykov.b52"
http://mattst88.com/programming/AssemblyProgrammersJournal/issue/9/
Kalmykov brilliantly demonstrated writing binaries even by bare typing from keyboard into final file (no hexeditor, no nice program as your one...)
It is quite short but very nutritive article and every asm programmer should read it at least once in life to appreciate handy asm compiler and handy editor he/she usually has the most of life.
here its begin
Quote:
What is 'extreme conditions' ? When you are sitting in front of a computer with only MS-DOS installed without any compilers, hex editors, shells, debuggers and you need to recover lost data, delete virus, or write a new one. This is an extreme conditions. Most of programmers won't be able to do anything, most of administrators think that this computer is 100% secured. But this won't stop the assembler programmer ...
Post 24 Jan 2013, 12:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.