Re: All is right !
- From: "Wolfgang Kern" <nowhere@xxxxxxxx>
- Date: Fri, 18 Apr 2008 23:34:34 +0200
almas wrote:
Guten Tag Wolfgang.:) Bon Jour! or similar, my French is restricted to doing it :)
Hi everybody
I try the solution, it just cost 70 bytes. I choose a very small size of
file.
If code size is your main concern you can make CALLs out of the
two identical parts in the conversion:
But you know that DOS files always occupy a whole cluster on disk and
that the PSP is 256 bytes large, beside the environment copy anyway.
I limit my modular code to disk sector bounds (multiple of 512 bytes).
ie: also just 32(26)+22(18)+13(8) = 71(52) code-bytes, the figures
in brackets mean without the out-commented functionality.
_____________________
mov esi,0082h ; I see, you assume a space before the parameters
;cmp byte [esi-2],0 ; a few buyes more, but perhaps useful
;jz error ;if commandline is empty
lodsw ;get both bytes at once
call convert ;modify AL set carry/NC on error/GOOD
jc error
shl al,4
exch al,ah ;save first and use second yet
call convert ;call the same again
jc error
or al,ah
mov offset hexa,AL
jmp short display_quit
convert:
; cmp al,30h ;I'd put this in
; jc oh_no ;jc == jb
cmp al,3ah
jc num
cmp al,41h
jc oh_no
cmp al,46h
cmc ;invert the carry-bit (error if NoCarry >46h)
jc oh_no
sub al,07h
num:
sub al,30h
oh_no:
ret ;the last SUB will always result in NoCarry
;while any error got a set Carry-flag now.
error:
; mov dx,errtxt
; jmp short error_quit
display_quit:
mov dx,txt
error_quit:
mov AH,09
int 21h
ret ;it will work, even I'd always use:
; mov ax,4c00h ;because DOS will restore its stack and
; int21h ;segment-registers on termination then.
txt:
hexa:
errtxt: ...
______________________________
mov si,0082h ; Sure, i must respect the syntax*** remove this line: > jmp short high_size
lodsb
cmp al,3Ah ; what if one typed any of !"+-*().. or an ALT-num<30 ?
jb chiffre_d ; d for ten : ( forty, fivety, 60 and so long)
cmp al,41h ; is it an Hexa letter ?
jb error
cmp al,46h
ja error ;
sub al,07
chiffre_d: ; can be 0 to 9 but no think else
( It can be anything else if you input characters with code
below 30h ie: !"#$%^&()*+,-./ 20..2Fh)
sub al,30h ; "0" > 00h "9" become 09h
*** and this label become obsolete then: > high_size:
SHL AL,4 ; (= *16 and clears low 4 bits also) (00,01..0Fh becomes
00,10..F0h)
xchg ax,bx ; i just use 1 byte sure "mov bl,al" do the same.
I see, it's OK if you prefer short code.
lodsb*** sub al,07h ; the difference of "41h-3Ah" = 7
cmp al,3Ah
jb chiffre_u ; U like Unit
cmp al,41h ; for Unit, i have not to Rotate On Left
jb error ; so it just need One Sub al, [a value]
cmp al,46h
ja error
chiffre_u: ; > *** same as mentioned above ...
sub al,30h ; if it was 41..46 then we sub 7 'and' sub 30h (sub 37h)
***; > low_size:
add ax,bx ; it use 2 bytes ; but OR AL,BL is more logic.
; you have lower nibble (4 bits) in AL now
; and higher nibble shifted (*16) and saved in BL.
; Two hex-characters wont ever produce more than one byte.
; It will work if you add AX,BX, but I'd use OR AL,BL
; or does your DOS support Unicode ? :) ... then mov AH,0 would do it.
mov offset hexa,ax
; *** why two characters ? (the 2nd will be zero):"?" or so...
; mov dx,offset hexa jmp short display_it int 20h
error:
mov dx,offset txt ; i display the "how o use" and the result in same
time
mov ah,9
int 21h
ret ; just cost 1 byte, int 20h also works
Yes, as long it's a DOS-.com file and you don't alter the stack.
txt db: "Asci2Hex" ,9 ; Yes no $ here !display > text
hexa db: 32,10,36 ; Ascii "10" go line below "36" terminate
Right, but if you like any next line to start left-most, then
you should insert a CR as well: hexa: db 32,10,13,36
__
wolfgang
.
- Follow-Ups:
- Re: All is right !
- From: Wolfgang Kern
- Re: All is right !
- References:
- All is right !
- From: almas
- Re: All is right !
- From: almas
- Re: All is right !
- From: Wolfgang Kern
- Re: All is right !
- From: almas
- Re: All is right !
- From: Wolfgang Kern
- Re: All is right !
- From: almas
- All is right !
- Prev by Date: powerpc sync and eieio instructions
- Next by Date: Language help! please help me polish my language as native as possible
- Previous by thread: Re: All is right !
- Next by thread: Re: All is right !
- Index(es):
Relevant Pages
|