flat assembler
Message board for the users of flat assembler.
Index
> Main > Byte to hex, once again. Goto page Previous 1, 2, 3 Next |
Author |
|
Alphonso 17 Aug 2010, 09:45
LocoDelAssembly wrote: 29 bytes and returns what I believe it is the correct answer. The preferred way, whether it's the correct way is IMO up to Fanael to confirm if high and low ordering is required. Fanael would you also clarify if using the stack is allowed? Nice code examples guys. |
|||
17 Aug 2010, 09:45 |
|
Fanael 17 Aug 2010, 11:25
p=117915 (Alphonso), p=117916 (LocoDelAssembly): accepted.
Alphonso wrote: The preferred way, whether it's the correct way is IMO up to Fanael to confirm if high and low ordering is required. Alphonso wrote: Fanael would you also clarify if using the stack is allowed? Picnic, LocoDelAssembly: your codes are violating second (call is an unconditional branch, yes, but nonetheless a branch) and fourth (stack!) rule. Okay, maybe it's time to relax the rules a little bit. New rules (the competition with original rules is still running, though): * The code has to compile fine with use32 and use64, * No conditional branches, * The same goes for conditional moves, * No memory accesses, except using stack and writing the result somewhere. According to these rules, I can do nothing else than accept your codes |
|||
17 Aug 2010, 11:25 |
|
mindcooler 17 Aug 2010, 12:52
Picnic wrote: 28 bytes for 32/64. Routine must be called. I thought of doing something like this to make it loop once. You could do an explicit returnaddress push at the start to make it inlineable. _________________ This is a block of text that can be added to posts you make. |
|||
17 Aug 2010, 12:52 |
|
edfed 17 Aug 2010, 14:39
or make it loop as many cases you want...
Code: call @f xchg al,ah call @f xchg al,bl call @f xchg al,bh @@: ret excellent code. maybe a rule would be to imposre the conversion of a single byte in AL, and return the result in AX. or convert the byte from a memory indexed by ESI, and write in a memory indexed by EDI. with a count of bytes to convert in ECX. |
|||
17 Aug 2010, 14:39 |
|
Alphonso 17 Aug 2010, 15:59
Probably as much as I can do with mul.
Code: xor ecx,ecx mov bx,3030h mov cl,7 mov ah,al shr ah,4 and al,0fh add ebx,eax mul ecx shr ax,6 and al,1 mul ecx add ebx,eax ;bx=Ascii |
|||
17 Aug 2010, 15:59 |
|
MHajduk 17 Aug 2010, 22:20
28 bytes, ASCII output in AX
Code: xor ebx, ebx mov dl, 9 mov ah, al shr ah, 4 and al, 0Fh cmp dl, al adc bl, bl cmp dl, ah adc bh, bh add ax, 0x3030 imul ebx, ebx, 7 add eax, ebx |
|||
17 Aug 2010, 22:20 |
|
guignol 18 Aug 2010, 02:40
Code: mov ah,al shr ah,4 and al,0xF add ax,0x4141 cmp al,0x4A jnbe @f sub al,0x11 @@: cmp ah,0x4A jnbe @f sub ah,0x11 @@: ; 25 bytes Last edited by guignol on 18 Aug 2010, 17:47; edited 5 times in total |
|||
18 Aug 2010, 02:40 |
|
MHajduk 18 Aug 2010, 08:37
Unfortunately, guignol, your program compiles to 29 bytes for 32 and 64-bit mode (add use32 or use64 at the beginning of your code to check it). Like that:
Code: use32 ; use64 ; ; guignol's code here... ; |
|||
18 Aug 2010, 08:37 |
|
Fanael 18 Aug 2010, 10:09
Alphonso: accepted.
MHajduk: accepted. guignol: rejected, conditional branches are not allowed. Current standings (parenthesized submissions conform only to relaxed rules): Code: (1. LocoDelAssembly #4 - 27) 2. MHajduk - 28 (2. Picnic - 28) (4. LocoDelAssembly #3 - 29) 4. Alphonso #3 - 29 6. Alphonso #2 - 31 6. LocoDelAssembly #2 - 31 8. LocoDelAssembly #1 - 33 9. Alphonso #1 - 37 10. chaoscode - 49 |
|||
18 Aug 2010, 10:09 |
|
guignol 18 Aug 2010, 10:20
MHajduk wrote: Unfortunately, guignol, your program compiles to 29 bytes for 32 and 64-bit mode MHajduk wrote: BTW, you can't use conditional branches. Code: mov dl, 9 |
|||
18 Aug 2010, 10:20 |
|
MHajduk 18 Aug 2010, 11:04
guignol wrote: At least, [my] code is readable guignol wrote:
Code: cmp dl, al adc bl, bl cmp dl, ah adc bh, bh (I mean, that we can't just write something like that: 'cmp 9, al'). |
|||
18 Aug 2010, 11:04 |
|
guignol 18 Aug 2010, 11:12
MHajduk wrote: Hmm... I was sure that my code is so simple, obvious and trivial guignol wrote: to reverse compared arguments. What for? |
|||
18 Aug 2010, 11:12 |
|
MHajduk 18 Aug 2010, 11:23
guignol wrote: I can see that. When al >= 10 (ah >= 10) then bl (bh) is set to 1 (we can use here one of the 'setX' instructions, but it would give 3 bytes here instead 2 for 'adc bl, bl' and 'adc bh, bh'). |
|||
18 Aug 2010, 11:23 |
|
guignol 18 Aug 2010, 11:52
MHajduk wrote: We need CF flag set for al >= 10 and ah >= 10. I'm asking why do you use some register instead of an immediate value? |
|||
18 Aug 2010, 11:52 |
|
MHajduk 18 Aug 2010, 12:13
"Baby", that's good, hahaha...
You can all do comparisons this way: Code: cmp al, 10 (...) cmp ah, 10 To reverse inequalities you have to use two 'cmc' (2 extra bytes) or something like that - that is a monkey business. I tried it all yesterday and I'm almost sure that we probably can't minimize it further. It would be superb if we can use such instructions like 'aam 16' (only two bytes!) to separate al nibbles: Code: aam 16; ah := al / 16, al := al mod 16 [EDIT]Corrected typo '%' -> '/'[/EDIT] Last edited by MHajduk on 21 Aug 2010, 14:04; edited 1 time in total |
|||
18 Aug 2010, 12:13 |
|
guignol 18 Aug 2010, 12:41
Code: mov dl,9 cmp dl,al cmp dl,ah ; 6 bytes Code: cmp al,10 cmp ah,10 ; 5 bytes |
|||
18 Aug 2010, 12:41 |
|
MHajduk 18 Aug 2010, 13:00
guignol wrote:
Code: cmp al, 10; CF = 1 when al < 10, CF = 0 when al >= 10 Code: ; ;"cmp 10, al" ; cmp reg8, al ; CF = 1 when reg8 < al, CF = 0 when reg8 >= al ; i.e. CF = 1 when al > reg8, CF = 0 when al <= reg8 ; If reg8 = 9 we have exactly what was expected: ; CF = 1 when al > 9, CF = 0 when al <= 9 ; i.e. CF = 1 when al >= 10, CF = 0 when al < 10 |
|||
18 Aug 2010, 13:00 |
|
guignol 18 Aug 2010, 14:09
MHajduk wrote: and doing 'adc bl, bl' and 'adc bh, bh' would be nonsense after 'cmp al, 10' and 'cmp ah, 10' respectively. But some falafel won't like them. I bet! it's hard to jump when you're round. Ok. Code: add ax, 0x3030 imul ebx, ebx, 7 add eax, ebx You add 7 to 48? |
|||
18 Aug 2010, 14:09 |
|
MHajduk 18 Aug 2010, 14:39
guignol wrote: But some falafel won't like them. BTW, thinking of Fanael's nick, I got that there should exist an angel who cares about FASM coders. I guess he/she should be named Fasmael. guignol wrote:
Code: / | 0, if al < 10 bl = < | 1, if al >= 10 \ / | 0, if ah < 10 bh = < | 1, if ah >= 10 \ Code: add ax, 0x3030 So, we need correction equal to 7 for al, ah >= 0x3A. This is performed in the next two instructions: Code: imul ebx, ebx, 7 add eax, ebx Code: / | 0, if al < 0x3A bl = < | 7, if al >= 0x3A \ / | 0, if ah < 0x3A bh = < | 7, if ah >= 0x3A \ |
|||
18 Aug 2010, 14:39 |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.