flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2 |
Author |
|
windwakr 27 Jul 2008, 02:46
Neat, but confusing.
|
|||
![]() |
|
windwakr 27 Jul 2008, 15:48
Madis731 has a base 2 to 36 or anything in between program.
In this thread. |
|||
![]() |
|
Madis731 27 Jul 2008, 16:27
Hmm, interesting how compilers work
![]() ![]() Intel C++ 10.1.022: Code: ?chartobcd@@YAEE@Z PROC NEAR ; parameter 1: ecx $B1$1: ; Preds $B1$0 mov eax, 1717986919 ;3.14 movzx ecx, cl ;3.10 imul ecx ;3.14 mov r8d, ecx ;3.14 sar r8d, 31 ;3.14 sar edx, 2 ;3.14 sub edx, r8d ;3.14 lea r9d, DWORD PTR [rdx+rdx*4] ;3.14 add r9d, r9d ;3.14 sub ecx, r9d ;3.14 shl edx, 4 ;3.21 or ecx, edx ;3.31 mov eax, ecx ;3.31 ret ;3.31 ALIGN 2 ; LOE ; mark_end; ?chartobcd@@YAEE@Z ENDP Some comments: -the magic number 1717986919 in hex is 66666667 -only one LEA and IMUL -most of the instructions are 1 uop Statistics too: -It takes 8 core clock cycles at best to complete -The instructions need 15 uops |
|||
![]() |
|
Shahada 27 Jul 2008, 17:52
windwakr wrote: Madis731 has a base 2 to 36 or anything in between program. Thanks windwakr & Madis731, this is what I need. |
|||
![]() |
|
windwakr 28 Jul 2008, 21:07
I just found some small routines for binary to bcd
#1: does binary to unpacked bcd up to 99 put number to convert in al uses all of ax Code: aam #2: does binary to packed bcd up to 99 number in al uses all of ax Code:
aam
aad 16
|
|||
![]() |
|
neville 29 Jul 2008, 05:52
Shahada wrote: Thanks, but what I need is a bin to whatever base routine, like the one from Microsoft C library, not only bin2dec. This FAMOS guy neville said he has up to base 36 routine and I want to see it. Here's the code. After windwankr's "rejection" ![]() Code: ;--------------------------------------------------------------------------- ; DISPLAY 32-BIT VALUE IN ANY BASE 2-36+ ;--------------------------------------------------------------------------- ;enter with dx=row/col of LSD (RHS), bx=page/colour, 32-bit dword in EAX, ;required number base in dword CS:NUMBASE. Saves all regs! ;leading zeroes automatically suppressed! NB: prints right to left! D32BITV: PUSHAD D32NEXT: PUSH EBX PUSH EDX XOR EDX,EDX ;initialise remainder MOV EBX,[CS:NUMBASE];required base (for divisor) DIV EBX ;DX=decimal next sig digit 0-9 binary MOV ECX,EAX ;save remaining value MOV EAX,EDX ;get decimal digit CALL NYBL2HEX ;convert to ascii POP EDX ;get cursor position POP EBX ;get colour CALL DCHARP ;display digit DEC DL ;shift cursor to left NB: LEFT! MOV EAX,ECX ;restore decimal value OR EAX,EAX ;=0? JZ D32DONE ; -y, done JMP D32NEXT ; -n, do next digit D32DONE: POPAD RET ;exit with EAX=0, EDX=MSD cursor position ;--------------------------------------------------------------------------- ; DISPLAY SINGLE CHAR WITH POSITION OPTION (adapted for DOS from FAMOS) ;--------------------------------------------------------------------------- ;enter DCHARP with reqd position (row/col) in dh/dl, char in al DCHARP: PUSHA CALL SETCUR MOV AH,0EH INT 10H POPA RET ;--------------------------------------------------------------------------- ; SET CURSOR POSITION (adapted for DOS from FAMOS) ;--------------------------------------------------------------------------- ;enter SETCUR with reqd position (row/col) in dh/dl, preserves al SETCUR: MOV AH,2 INT 10H RET ;--------------------------------------------------------------------------- ; CONVERT NYBLLE TO EQUIVALENT HEX DIGIT ;--------------------------------------------------------------------------- ;enter with valid nybble in al (bits 4-7 = 0) NYBL2HEX: ADD AL,30H CMP AL,3AH JB NYBLDONE ADD AL,07 NYBLDONE: RET ;exit with ascii code of 1 hex digit in al, ah=0 ;--------------------------------------------------------------------------- ; DATA (accessed via CS:) ;--------------------------------------------------------------------------- NUMBASE: DD 00000010H ;base 16 = default _________________ FAMOS - the first memory operating system |
|||
![]() |
|
neville 29 Jul 2008, 05:54
Oops, typo above...
That should be "windwakr". No offence intended ![]() |
|||
![]() |
|
DOS386 29 Jul 2008, 06:38
Madis731 wrote: Intel C++ 10.1.022: Seems to be 64-bit code ![]() _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
![]() |
|
Shahada 29 Jul 2008, 06:58
Thanks neville, good example for me.
|
|||
![]() |
|
Madis731 29 Jul 2008, 09:06
Sorry about 64-bit, but any assembly-programmer can change it to 32-bit on-the-fly ... I think. R** => E** and registers above r8 can be changed to memory references (maybe even stack).
This particular example is rather easy if your willing to sacrifice ebx, esi, edi, ebp. I would not touch stack neither ebp. Ebx is dangerous too ![]() so... Code: proc chartobcd ;ecx=in numchar, eax=out bcd mov eax, 66666667h movzx ecx, cl imul ecx mov esi, ecx sar esi, 31 sar edx, 2 sub edx, esi lea edi, [edx*5] add edi, edi ; you can make these two lines sub ecx, edi ; sub ecx,edi / sub ecx,edi shl edx, 4 or ecx, edx mov eax, ecx ret endp ...you can, of course get rid of edi by changing it to esi (if you see the code, its free) and then you have one less register used. It is there for optimal performance so its your own choice. |
|||
![]() |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.