Author Topic: How to read 5 Bits at once  (Read 10003 times)

Offline Siko7

  • Jr. Member
  • *
  • Posts: 3
How to read 5 Bits at once
« on: November 03, 2018, 10:32:09 AM »
Hi Everyone

I would like to program a Base32 encoder. For this I have to split the binary data I get, into 5 bits and read them one after the other. What is the best way to solve this?
Unfortunately I am a beginner in assembly.

Thanks for helping

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: How to read 5 Bits at once
« Reply #1 on: November 04, 2018, 07:30:28 AM »
Perhaps for a beginner, you shouldn't write a "Base32 encoder" just yet. Show some code or else your question doesn't sound legit at all.

p/s Frank? ;D

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to read 5 Bits at once
« Reply #2 on: November 04, 2018, 09:52:01 PM »
Thanks dreamCoder,
I have to agree that a Base32 encoder does not sound like a good beginner project! Where do you stand, Siko7? Got an algorithm? I think I used to know what a Base32 encoder was, but that memory is paged out now. Sorry.

Best,
Frank


Offline Siko7

  • Jr. Member
  • *
  • Posts: 3
Re: How to read 5 Bits at once
« Reply #3 on: November 05, 2018, 07:39:54 PM »
Here you can read what base32 is: https://en.wikipedia.org/wiki/Base32

For the moment i just have this code which is based on the hexdump code.

SECTION .data         ; Section containing initialised data
Str:   db " 00 00 00 00 00",10
   BASELEN equ $-BASEStr

   Digits:   db "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
   
   
SECTION .bss         ; Section containing uninitialized data

   BUFFLEN   equ 5      ; We read the file 5 bytes at a time
   Buff:    resb BUFFLEN   ; Text buffer itself

   StringOut db "  ",10   ;
   Stringoutlen equ $-StringOut
   

SECTION .text         ; Section containing code

global    _start         ; Linker needs this to find the entry point!
   
_start:


Read:
   mov eax,3      ; Specify sys_read call
   mov ebx,0      ; Specify File Descriptor 0: Standard Input
   mov ecx,Buff      ; Pass offset of the buffer to read to
   mov edx,BUFFLEN      ; Pass number of bytes to read at one pass
   int 80h         ; Call sys_read to fill the buffer
   mov ebp,eax      ; Save # of bytes read from file for later
   cmp eax,0      ; If eax=0, sys_read reached EOF on stdin
   je Done         ; Jump If Equal (to 0, from compare)