ASSEMLY - String Compression, Help Plz
|
|||
|
Rank: ? (1)
Member #: 27655 |
Hello!
I need to make a programm in assembly (it´s better to use Emu8086) that recieves the STRING from the keyboard and than compress it in this way: input string--> aaabbcddd output string--> 3a2b1c3d. I know that it is very simple, but I´m just a beginner and can´t make it. I have just one day till tomorrow afternoon. Hope You´ll help me. Thnks I have an exemple of a code here, but it doesn´t work .model small .data inputstr db 80 dup (' '),'$' ;uncompressed input string & read from keyboard outputstr db 80 dup (' '),'$' ;compressed output string & displayed .code start: mov ax,@data ;Prepare access to Data Segment mov ds,ax mov ah,0Ah ;DOS function "Read from file or device" mov bx,0 ;Standard input device (keyboard) mov cx,80 ;Maximum length of read input string mov dx,offset inputstr ;Memory address of read input string int 21h ;Call DOS function dispatcher sub ax,2 ;Decrement by 2 the actual input string length(EOL) mov si, offset inputstr mov di, offset outputstr L1: mov bx,si ;Check if we arrived the end of input string (While-type loop) sub bx,offset inputstr cmp bx,ax ;Compare with the length of read input string je L4 ;If so jump to finish mov cl,1 ;initialize the character counter L2: mov dl,[si] ;Read the character cmp dl,[si+1] ;Compare with the next character jne L3 ;If not equal jump to constructing output string inc cl ;If equal increment counter inc si ;And address of next character jmp L2 ;Repeat counting the current character L3: mov [di],dl ;Construct the compressed output string. Save character inc di add cl,'0' ;Simple single digit conversion to ASCII mov [di],cl ;Save the counter inc di ;Prepare for next character inc si ; jmp L1 ;Repeat for next character (End of While-type loop) L4: mov ah,09h ;DOS function "Write string to standard output" mov dx,offset outputstr ;Display decompressed output string int 21h ;Call DOS function dispatcher mov ah,4ch ;DOS function "Exit" int 21h ;Call DOS function dispatcher end start |
||
|
|||
|
|||
|
Rank: ? (5)
Member #: 28723 |
hi,
there were some mistakes, especially the input function 0Ah /Int 21h works a bit different, but the general idea was ok, seems to be working now Code:
|
||
|
Please login or register to post a reply.