Re: Insert a byte




"Herbert Kleebauer" <klee@xxxxxxxxx> ha scritto nel messaggio
news:48EA4C8C.11A1636F@xxxxxxxxxxxx
rio wrote:
"Herbert Kleebauer" <klee@xxxxxxxxx> ha scritto nel messaggio

it will be interesting how all you write the routines
that can transform a 8 bit stream in a 7 bit stream
and vice versa in C
in the range
32...159
| |
0...127

Sorry, but I don't understand what you mean.

you have a stream of 8 bit so each chars is 0..255
write the routines that convert that stream to
a stream where each char is 0..127 or 32..159

I still don't get it. You can't pack a 8 bit binary in a 7 bit binary.

in one no, but in 2 yes

Either you have to drop halve of the input bytes or you have to
output 8 bytes for 7 input bytes.

is the same of echo() function below you wrote
?>if not [%1]==[] goto :sub
?>echo
hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>conv.com

in the line above
it seems echo() convert the char array of 6 bits
to array of 8 bits (written in conv.com)

echo doesn't convert anything, it just writes the given ascii string to
conv.com.
The program conv.com is written with opcodes in the printable ascii range
only
(without the poisoned characters &<>%!^|).


i say only to convert one char array of 7 bits
to array of 8 bits and vice versa. (in the way not waste space in the
7 bits array)

Why should this be complicated in C?

main()
{int i;
unsigned char in[7]={0x22,0x44,0x66,0x88,0xaa,0xee,0xff};
unsigned char out[8];

out[7]=0;
for (i=0; i<7; i++)
{out[i] = in[i] & 0x7f; out[7] = (out[7]<<1) + (in[i]>>7);}


for (i=0; i<7; i++) printf("%2x ",in[i]); printf("\n");
for (i=0; i<8; i++) printf("%2x ",out[i]); printf("\n");
}

the problem was for the 7bit to 8bit
anyway above is not complete (and my is not test enought 1 only )
anyway in confront to C the language i wrote it is 100 times better


section _DATA use32 public class=DATA

extern ReadFile
extern WriteFile
extern GetStdHandle
extern CloseHandle
extern FlushFileBuffers
extern GetCommandLineA

global GetStdIo
global CloseStdIo
stdin dd -1
stdout dd -1
stderr dd -1

%define STD_ERROR_HANDLE 0FFFFFFF4h
%define STD_INPUT_HANDLE 0FFFFFFF6h
%define STD_OUTPUT_HANDLE 0FFFFFFF5h
%define NL 13,10
%define Space 6

helptxt db "Errore di argomenti" , NL
db "Uso:" , NL
db "thisProg -To7Bit < file.in > file.out" , NL
db "thisProg -To8Bit < file.in > file.out" , NL, 0, 0

MyTable:
db 5, 16, 16, 16, 16, 16, 16, 16, 16, 6 ; 0
db 5, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 1
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 2
db 16, 16, 6, 9, 16, 9, 3, 3, 9, 16 ; 3
db 9, 9, 9, 9, 9, 9, 2, 16, 0, 0 ; 4
db 0, 0, 0, 0, 0, 0, 0, 0, 16, 16 ; 5
db 9, 9, 9, 9, 3, 1, 1, 1, 1, 1 ; 6
db 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; 7
db 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; 8
db 2, 16, 16, 16, 9, 2, 16, 1, 1, 1 ; 9
db 1, 1, 1, 2, 2, 2, 2, 2, 2, 2 ; 10
db 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; 11
db 2, 2, 2, 16, 9, 16, 16, 16, 16, 16 ; 12
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 13
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 14
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 15
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 16
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 17
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 18
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 19
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 20
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 21
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 22
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 23
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 24
db 16, 16, 16, 16, 16, 16, 0, 0, 0, 0 ; 25


section _TEXT use32 public class=CODE

; u32 PrendiArgomenti(u32** arr, u32 NArrElements)
; ritorna il numero di argomenti presi CF==0 tutto ok
; alla fine un puntatore permesso del vettore arr
; punta a un array di char che descrive l'argomento
; che risulta essere finito da ' ' spazio o tab
; se non inizia con ' oppure "
; altrimenti e' finito rispettivamente da ' e da "
; altrimenti se errore es il vettore e' tutto riempito
; o i parametri sono sbagliati: ritorna
; il numero di argomenti ed CF==1
; 0j,4i,8b, 12ra,16P_arr, 20P_limite
PrendiArgomenti:
push ebx
push esi
push edi
mov ebx, dword[esp+ 16]
cmp dword[esp+20], 0
jle .e0
cmp ebx, 0
jne .a
..e0: xor eax, eax
..e: stc
jmp .z
..ee: mov eax, ecx
jmp short .e
..a: call GetCommandLineA
mov esi, eax ; nel puntatore 0 vi e' il primo argomento
cmp eax, 0
je .e0
xor ecx, ecx
xor eax, eax
mov edx, dword[esp+ 20]
jmp short .2 ; c=contatore; r=il limite;
..0: inc esi
mov al, [esi]
cmp eax, 0
je .e
cmp eax, edi
jne .0
..1: inc esi ; leva gli eventuali spazi prima
..2: mov al, [esi]
cmp byte[MyTable+eax], Space
je .1
cmp eax, 0
je .3
mov [ebx+ecx*4], esi ; assegna al puntatore il primo
carattere
inc ecx
cmp ecx, edx
jae .ee
mov edi, eax
cmp eax, '"'
je .0
cmp eax, 39
je .0
..2a: inc esi
..2b: mov al, [esi]
cmp eax, 0
je .3
cmp byte[MyTable+eax], Space
jne .2a ; scorre la parola
jmp short .1
..3: mov eax, ecx
clc
..z:
pop edi
pop esi
pop ebx
ret 8

GetStdIo:
jmp short .1
..e: mov eax, -1
stc
jmp .z
..1: push STD_ERROR_HANDLE
call GetStdHandle
mov [stderr], eax
cmp eax, -1
je .e
push STD_INPUT_HANDLE
call GetStdHandle
mov [stdin], eax
cmp eax, -1
je .e
push STD_OUTPUT_HANDLE
call GetStdHandle
mov [stdout], eax
cmp eax, -1
je .e
cmp eax, [stdin]
je .e
..2: xor eax, eax
..3: clc
..z:
ret

FlushCloseHandle:
push esi
push edi
mov esi, dword[esp+ 12]
cmp esi, -1
jne .1
..e: xor eax, eax
stc
jmp short .z ; bene a!=0
..1: push esi
call FlushFileBuffers
mov edi, eax
push esi
call CloseHandle
cmp eax, 0
je .e
cmp edi, 0
je .e
clc
..z:
pop edi
pop esi
ret 4

CloseStdIo:
mov edx, [stderr]
push edx
call FlushCloseHandle
mov edx, [stdin]
cmp edx, -1
je .1
push edx
call CloseHandle
..1: mov edx, [stdout]
push edx
call FlushCloseHandle
mov dword[stderr], -1
mov dword[stdin], -1
mov dword[stdout], -1
xor eax, eax
..z:
ret

; u32 NCharsRead GetNChars(u32 handle, u8* arr, u32 n)
;0j,4r,8c,12ra, 16P_a,20P_n,24P_h + 8
; 24 ,28 ,32
GetNChars:
push ecx
push edx
push esi
sub esp, 8
mov edx, dword[esp+ 24]
mov ecx, dword[esp+ 28]
mov esi, dword[esp+ 32]
mov dword[esp], 0
cmp edx, 0
je .e0
cmp esi, -1
je .e0
cmp ecx, 0
jg .1
jz .0
..e0: xor eax, eax
..e: stc
jmp short .z
..0: xor eax, eax
clc
jmp short .z
..1: mov eax, esp
push 0
push eax
push ecx
push edx
push esi
call ReadFile
mov ecx, eax
mov eax, [esp]
cmp ecx, 0
je .e
clc
..z:
lea esp, [esp+8]
pop esi
pop edx
pop ecx
ret 12

; u32 NCharsWritten PutNChars(u32 handle, u8* arr, u32 n)
;0j,4r,8c,12ra, 16P_h,20P_a,24P_n + 8
; 24 ,28 ,32
PutNChars:
push ecx
push edx
push edi
sub esp, 8
mov edi, dword[esp+ 24]
mov edx, dword[esp+ 28]
mov ecx, dword[esp+ 32]
mov dword[esp], 0
cmp edi, -1
je .e0
cmp edx, 0
je .e0
cmp ecx, 0
jg .1
jz .0
..e0: xor eax, eax
..e: stc
jmp short .z
..0: xor eax, eax
clc
jmp short .z
..1: mov eax, esp
push 0
push eax
push ecx
push edx
push edi
call WriteFile
mov ecx, eax
mov eax, [esp]
cmp ecx, 0
je .e
clc
..z:
lea esp, [esp+8]
pop edi
pop edx
pop ecx
ret 12

;u32 SPuts(u32 Handle, u32 String)
; scrive in Handle la stringa String
; 0j,4r,8c,12ra,16P_Handle,20P_Str + 8
; 24 28
SPuts:
push ecx
push edx
push edi
sub esp, 8
mov eax, dword[esp+ 28]
xor ecx, ecx
mov edx, eax
cmp dword[esp+24], -1
je .e
cmp eax, 0
jne .2
..e: stc
jmp short .z
..1: inc eax
inc ecx
..2: cmp byte[eax], 0
jne .1
mov edi, dword[esp+ 24]
mov eax, esp
push 0
push eax
push ecx
push edx
push edi
call WriteFile
mov ecx, eax
mov eax, [esp]
cmp ecx, 0
je .e
clc
..z:
lea esp, [esp+8]
pop edi
pop edx
pop ecx
ret 8

; u32 NcharRis BinTo7Bit(u8* Ris, u32 RisSize, u8* Origin, u32 n)
; 0k,4j,8i,12b,16ra,20P_r,24P_size, P_o, 28P_n+64
; 84 88 92 96
BinTo7Bit:
push ebx
push esi
push edi
push ebp
sub esp, 64
mov edi, dword[esp+ 84]
mov ebp, dword[esp+ 88]
mov esi, dword[esp+ 92]
mov ebx, dword[esp+ 96]
cmp ebp, 0
jle .e
cmp ebx, 0
jle .e
cmp edi, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: cmp esi, 0
je .e
add ebp, edi
jc .e
add ebx, esi
jc .e
mov [esp], ebp
mov [esp+4], ebx
xor eax, eax
xor ebp, ebp
xor ecx, ecx
..2: cmp edi, [esp]
jae .e
mov ax, [esi]
shr ax, cl
and al, 07Fh
add al, 32
mov [edi], al
cmp cl, 0
jne .3
mov cl, 7
jmp short .4
..3:
dec cl
inc esi
..4: inc edi
cmp esi, [esp+4]
jb .2
sub edi, dword[esp+ 84]
mov eax, edi
clc
..z:
lea esp, [esp+64]
pop ebp
pop edi
pop esi
pop ebx
ret 16

; u32 NcharRis Bit7ToBin(u8* Ris, u32 RisSize, u8* Origin, u32 n)
; 0k,4j,8i,12b,16ra,20P_r,24P_size, P_o, 28P_n+64
; 84 88 92 96
; 32..159
; | |
; 0..127
Bit7ToBin:
push ebx
push esi
push edi
push ebp
sub esp, 64
mov edi, dword[esp+ 84]
mov ebp, dword[esp+ 88]
mov esi, dword[esp+ 92]
mov ebx, dword[esp+ 96]
cmp ebp, 0
jle .e
cmp ebx, 0
jle .e
cmp edi, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: cmp esi, 0
je .e
add ebp, edi
jc .e
add ebx, esi
jc .e
dec ebx
mov [esp], ebp
mov [esp+4], ebx
xor ebp, ebp
xor ecx, ecx
xor ebx, ebx
xor edx, edx
jmp short .6a
..2: xor eax, eax
cmp edi, [esp]
jae .e
mov al, [esi]
sub al, 32
cmp esi, [esp+4]
jae .2a
mov ah, [esi+1]
sub ah, 32
..2a: mov cl, 7
sub cl, bl ; 7,1
shl ah, cl ; 6,2
..4: mov cl, bl ; 5,3
shr al, cl ; 4,4
or al, ah
mov [edi], al ; 3,5
cmp ebx, 7
jne .5
mov ebx, 0
jmp short .6 ; 2,6
..5: inc ebx
inc edi ; 1,7
..6: inc esi ; 0,8 non trattato
..6a: cmp esi, [esp+4]
jb .2 ; 7,1
sub edi, dword[esp+ 84]
mov eax, edi
clc
..z:
lea esp, [esp+64]
pop ebp
pop edi
pop esi
pop ebx
ret 16

; 0k,4j,8i,12b,16ra, 20P_fW,24P_fR
; 36 40
; 1064 1068
BinFileTo7Bit:
push ebx
push esi
push edi
push ebp
sub esp, 1044
mov edi, dword[esp+ 1064]
mov esi, dword[esp+ 1068]
mov dword[esp+ 4], 0
cmp edi, -1
je .e
cmp esi, -1
jne .0
..e: xor eax, eax
stc
jmp short .z
..0: mov ebp, esp
lea ebx, [esp+516]
..1: push esi
push 56
push ebp
call GetNChars
jc .e
cmp eax, 0
je .3
push eax
push ebp
push 512
push ebx
call BinTo7Bit
push eax
push ebx
push edi
call PutNChars
jc .e
jmp short .1
..3: mov eax, 1
..z:
lea esp, [esp+1044]
pop ebp
pop edi
pop esi
pop ebx
ret 8


; 0k,4j,8i,12b,16ra, 20P_fW,24P_fR
; 2068 2072
; 1064 1068
;
File7BitToBin:
push ebx
push esi
push edi
push ebp
sub esp, 2048
mov edi, dword[esp+ 2068]
mov esi, dword[esp+ 2072]
mov dword[esp+ 4], 0
cmp edi, -1
je .e
cmp esi, -1
jne .0
..e: xor eax, eax
stc
jmp short .z
..0: mov ebp, esp
lea ebx, [esp+520]
..1: push esi
push 512
push ebp
call GetNChars
jc .e
cmp eax, 0
je .3
push eax
push ebp
push 1024
push ebx
call Bit7ToBin
push eax
push ebx
push edi
call PutNChars
jc .e
jmp short .1
..3: mov eax, 1
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret 8


...start:
_main:
AsmMain:
push ebx
push esi
push edi
push ebp
sub esp, 2048
finit
call GetStdIo
jc .e
lea eax, [esp+40]
push 200
push eax
call PrendiArgomenti
jnc .1
..e: call CloseStdIo
mov eax, 1
stc
jmp .z
..1: mov esi, [stdin]
mov edi, [stdout]
cmp eax, 0
je .e
dec eax
..2: cmp eax, 1
jne .8
mov edx, dword[esp+ eax*4+40] ; I argomento
mov ebp, [edx]
mov eax, [edx+4]
and eax, 000FFFFFFh
cmp ebp, "-To7"
jne .4
cmp eax, "Bit"
jne .4
push esi
push edi
call BinFileTo7Bit
jc .e
jmp short .9
..4: cmp ebp, "-To8"
jne .8
cmp eax, "Bit"
jne .8
push esi
push edi
call File7BitToBin
jc .e
jmp short .9
..8: push helptxt
push edi
call SPuts
..9: call CloseStdIo
xor eax, eax
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret




the function for array 8 bits (0..255) to
array of 6bits (32..95)(should be Ascii) and vice versa seems quite easy.
than i wrote an unuseful? function for convert array 8 bits (0..255) to
array of 7bits (32..159)(ascii???) and vice versa and find some
difficulty

Ascii is 7 bit, no characters above 127.

in the vice versa step [from array of chars of value 32..159
to an array of chars of value 0..255] but nothing too much difficult
(at last in assembly)

If not too much difficult in assembly, then easy in C.



.



Relevant Pages

  • Re: Macro2D
    ... õ1, eax", 0 ... db "push striIIi", NL ... db ".2: cmp edi, ebp", NL ... db ".4: mov eax, edi", NL ...
    (alt.lang.asm)
  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: recvfrom
    ... push ebx ... mov eax, ... cmp eax, SOCKET_ERROR ...
    (alt.lang.asm)