flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2, 3 Next |
Author |
|
vid 15 Aug 2010, 19:42
to hexadecimal what? two ascii chars in AX? in memory? zero terminated? Or whatever goes?
|
|||
![]() |
|
Fanael 15 Aug 2010, 19:52
vid wrote: Or whatever goes? |
|||
![]() |
|
chaoscode 15 Aug 2010, 20:25
Code: mov ah,al shr ah,4 and ax,0x0F0F rol ax,8 mov ebx,msg xlatb rol ax,8 xlatb msg db "0123456789ABCDEF" edit: added code tags Last edited by chaoscode on 15 Aug 2010, 22:28; edited 1 time in total |
|||
![]() |
|
LocoDelAssembly 15 Aug 2010, 20:45
chaoscode, you're violating the last rule.
|
|||
![]() |
|
chaoscode 15 Aug 2010, 20:54
Code: mov ah,al shr ah,4 and ax,0x0F0F add ax,0x3030 cmp al,0x39 jna @f add al,7 @@: cmp ah,0x39 jna @f add ah,7 @@. EDIT. added quote tags Last edited by chaoscode on 15 Aug 2010, 22:29; edited 1 time in total |
|||
![]() |
|
LocoDelAssembly 15 Aug 2010, 21:06
Now you violated the 2nd rule
![]() |
|||
![]() |
|
chaoscode 15 Aug 2010, 22:02
hmpf... it's quite difficult^^
|
|||
![]() |
|
vid 15 Aug 2010, 22:14
I presume external functions are not allowed either
![]() chaoscode: please use [code] tags around your code. |
|||
![]() |
|
Fanael 15 Aug 2010, 23:49
vid wrote: I presume external functions are not allowed either ![]() chaoscode wrote: hmpf... it's quite difficult^^ ![]() |
|||
![]() |
|
mindcooler 15 Aug 2010, 23:55
Based on Revolution's. Violates #1.
AL -> AX Code: mov ah,al shr al,4 cmp al,10 sbb al,069h das xchg ah,al and al,$0f cmp al,10 sbb al,069h das _________________ This is a block of text that can be added to posts you make. |
|||
![]() |
|
chaoscode 16 Aug 2010, 00:03
Code: use64 format elf64 executable entry start start: mov eax,0 @@: cmp eax,0 mov ax,0xE5 call func mov ax,0x9A call func ret func: mov ah,al shr ah,4 and ax,0x0F0F mov dx,ax xor bx,bx add dl,0xF6 rcl bl,1 ror bl,1 sar bl,7 and bl,0x07 add al,bl add dh,0xF6 rcl bh,1 ror bh,1 sar bh,7 and bh,0x07 add ah,bh add ax,0x3030 ret |
|||
![]() |
|
Alphonso 16 Aug 2010, 05:31
Code: xor ah,ah ; can we assume ah=0 ? mov dx,ax ; could push but the stack is technically a memory op, isn't it? mov bx,3030h ; ascii offset mov cx,110ah ; ch=17, cl=10 shr al,4 ; upper hex div cl ; result = 0 for 0 to 9, 1 for A to F add bh,ah ; add remainder to result BX, 0 to 9 = 0 to 9, A to F = 0 to 5 mul ch ; for 0 to 9 = 0, for A to F add +17 ascii offset add bh,al ; add to result mov ax,dx ; this could have been a pop if memory op allowed and al,0fh ; lower hex div cl ; as above add bl,ah ; mul ch ; add bl,al ; BX = hex ascii of AL Not very small, 33 Bytes for 16 and 37 Bytes for 32/64. |
|||
![]() |
|
LocoDelAssembly 16 Aug 2010, 05:58
OK, big people is also getting in so I think it is OK to publish a spoiler
![]() Code: ror ax, 4 and al, $0F shr ah, 4 mov dh, 9 irps nibble, al ah { cmp dh, nibble sbb dl, dl and dl, 'A' - '9' - 1 add nibble, dl } add ax, '00' This one is 33 bytes in both 32- and 64-bit. AH holds least significant nibble intentionally. |
|||
![]() |
|
Tyler 16 Aug 2010, 06:02
Code: xor al,al mov byte[buf], 0 mov byte[buf+1],0 buf rb 2 How's that? ![]() |
|||
![]() |
|
vid 16 Aug 2010, 09:04
Tyler wrote:
That's wrong. It ought to be mov byte [...], '0'. But otherwise - good solution! |
|||
![]() |
|
Fanael 16 Aug 2010, 09:36
Hehe, it could be optimized further:
Code: xor al,al mov word [buf], '00' buf rb 2 ![]() chaoscode: accepted, 49 bytes. Alphonso: accepted. LocoDelAssembly: accepted. |
|||
![]() |
|
Alphonso 16 Aug 2010, 12:51
Well i suppose I could get rid of that horrible div.
Code: mov ah,al shr ah,4 ; use 'shr al,4' and and al,0fh ; 'and ah,0fh' to output Loco nibbles :p mov ebx,eax xor ecx,ecx mov cl,7 mul ecx and eax,4040h shr eax,6 mul ecx add ax,3030h add ebx,eax ; BX = hex ascii of AL or use 'add eax,ebx' for AX = hex ascii of AL. |
|||
![]() |
|
LocoDelAssembly 16 Aug 2010, 15:16
OK, if storing the value reversed is OK (Intel CPUs are little endian), then my entry could be this:
Code: mov ah, al and al, $0F shr ah, 4 mov dh, 9 irps nibble, al ah { cmp dh, nibble sbb dl, dl and dl, 'A' - '9' - 1 add nibble, dl } add ax, '00' |
|||
![]() |
|
Picnic 16 Aug 2010, 20:46
28 bytes for 32/64. Routine must be called.
Code: Byte2Hex: mov ah, al shr al, 4 mov dh, 9 call @F xchg al, ah and al, 0Fh @@: cmp dh, al sbb dl, dl and dl, 7 add al, dl add al, '0' ret |
|||
![]() |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.