flat assembler
Message board for the users of flat assembler.

Index > Main > Reed-Solomon simple encoder in Assembly language?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 24 Oct 2021, 12:40
I have written a 21x21 QR code generator console app in Pascal, with the Reed-Solomon error correction encoder ported from C by someone.

I tried to rewrite my QR code generator from Pascal to FASM, and it did not work. This was my first attempt. The ECC (error correction code) generated by the Assembly code was either in null or with invalid bytes.

Is there any Reed-Solomon simple encoder example in FASM? (FYI, I have deleted the erroneous Assembly program Crying or Very sad )

It was a mess trying to rewrite Pascal code in Assembly, especially I am not well versed in stack frame. Confused
Post 24 Oct 2021, 12:40
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 01 Nov 2021, 11:46
Can you post a link to the Pascal source code?
Post 01 Nov 2021, 11:46
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 02 Nov 2021, 03:39
Hrstka wrote:
Can you post a link to the Pascal source code?


Hi, I have attached the Pascal source file on here since the link contains additional binaries for Win32 and Linux.

The Reed-Solomon encoder functions are as below:
Code:
  rs_init_gf(285);
  rs_init_code(7,0);
  rs_encode(19,@data[0],@ecc[0]);
  rs_free;    


The 285 value is fixed. 19 means the total codewords in Version 1 (21x21) QR Code.


Description: Pascal source
Download
Filename: QRCLI.txt
Filesize: 13.46 KB
Downloaded: 496 Time(s)

Post 02 Nov 2021, 03:39
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 02 Nov 2021, 09:42
Looks interesting. I would reserve a fixed amount of memory instead of calling GetMem and add some lookup tables in order to simplify the code. I may try to convert it to assembler if I have enough time. Are you using 32bit or 64bit instruction set?
Post 02 Nov 2021, 09:42
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 02 Nov 2021, 11:15
Hrstka wrote:
Looks interesting. I would reserve a fixed amount of memory instead of calling GetMem and add some lookup tables in order to simplify the code. I may try to convert it to assembler if I have enough time. Are you using 32bit or 64bit instruction set?


That's very good of you, it will be pleasant if you able to rewrite the Pascal code in Assembly.
I am using 32-bit instruction for Win32, but prefer 64-bit instruction for Linux. I am using Linux x64 since last few months.
Post 02 Nov 2021, 11:15
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 02 Nov 2021, 11:23
Hi, the following are some additional info to help understand the program.

1. Please refer to attached image, as that is what my QRCLI program was referring to,
* Version 1 (21x21, 23x23 if includes quiet zone)
* Byte encoding
* 14-chars max (although 21x21 allows up to 17 chars for byte encoding)
* Low error correction level (7%, that is 7 bytes of ECC)

2. The last three characters (15th, 16th , 17th) were not encoded as the bit pattern is different from the previous 14 characters. You may want to improve it or leave it as is (14-chars max)

3. The QRCLI program encodes a fixed length of 14 (regardless of the length of actual string) by substituting the rest with null bytes.

Thank you!


Description: The QRCLI program follows this specific size of QR code specification
Filesize: 102.46 KB
Viewed: 13762 Time(s)

qr.png


Post 02 Nov 2021, 11:23
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 05 Nov 2021, 08:30
Here is my assembly version. The code is 32bit to make it more universal. Targeted for Windows, but should be easy to adapt it for Linux as well. Instead of drawing the QR code to the screen I decided to create a bmp file. You just have to magnify the image to see it. The string is hard-coded, if you want to pass arguments on command line, you have to implement it.


Description: QR code generator, version 1.0
Download
Filename: QRCLI.asm
Filesize: 11.59 KB
Downloaded: 530 Time(s)

Post 05 Nov 2021, 08:30
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 31 Dec 2021, 13:41
Why has the FlierMate's Linux version disappeared?
Post 31 Dec 2021, 13:41
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 31 Dec 2021, 14:24
Hrstka wrote:
Why has the FlierMate's Linux version disappeared?


I'm sorry, it wasn't administrator's fault. I deleted quite a lot of stuffs today, because I was in bad mood this afternoon.....

If forum CP has a recycle bin, hopefully admin can restore this particular post.
Post 31 Dec 2021, 14:24
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 31 Dec 2021, 17:30
FlierMate wrote:
If forum CP has a recycle bin, hopefully admin can restore this particular post.
When the author of a post decides to delete it, the decision is respected and all the data is removed permanently. However sometimes I might be able to pull something from the backups.

Is this the file?


Description: QR code generator, Linux 32-bit version
Download
Filename: qrcli.asm
Filesize: 11.38 KB
Downloaded: 448 Time(s)

Post 31 Dec 2021, 17:30
View user's profile Send private message Visit poster's website Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 31 Dec 2021, 18:01
Tomasz Grysztar wrote:

Is this the file?


Yes, I have tested it again and it is the same file that I had uploaded.

Thank you very much, Tomasz, for the extra effort. Very Happy

Hrstka, thank you for your Assembly version in Win32-i386. Surprised

Added on 2 Jan 2022

I have created a repo for you and me, Hrstka:


Last edited by FlierMate on 09 Jan 2022, 11:33; edited 1 time in total
Post 31 Dec 2021, 18:01
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 03 Jan 2022, 15:11
Tomasz, thanks for restoring back the file.

FlierMate, I hope you will be in a better mood this year Very Happy . After reading your comments on GitHub, I realized that it would be a lot better to move the string to the beginning of the source file like this
Code:
text_to_encode equ 'Hello World!'
SIZE_QRDATA = 32
SIZE_QRECC  = 16    

and then
Code:
string   db text_to_encode,0    
Post 03 Jan 2022, 15:11
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 03 Jan 2022, 17:28
Hrstka wrote:

FlierMate, I hope you will be in a better mood this year Very Happy . After reading your comments on GitHub, I realized that it would be a lot better to move the string to the beginning of the source file like this
Code:
text_to_encode equ 'Hello World!'
SIZE_QRDATA = 32
SIZE_QRECC  = 16    

and then
Code:
string   db text_to_encode,0    


Thank you for the well wishes, and your enhancement. I think I will do it later , because I have just finished porting your QRCLI.asm to MenuetOS 64 GUI app!!

Update on 4 Jan 2022

Hi there, Hrstka, I have updated the repo accordingly. Thank you tor the nice idea!
Post 03 Jan 2022, 17:28
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 04 Jan 2022, 08:25
Hi Hrstika, sorry to bother you again.

Firstly, want to let you know the MenuetOS-64 version of qrcli.asm is at:
https://board.flatassembler.net/topic.php?t=22141

I found that our qrcli.asm (and qrcli.pas) are generating the correct 21x21 QR code, but somehow when I port it to MenuetOS 64 GUI app, the pixels might be drawn in wrong direction. Do you know what's wrong?

Please see image below (both with decoded string "What is this?")

Thanks to error correction, the tampered QR code can still be read and decoded successfully.


Description: The difference between QR codes of same encoded string
Filesize: 47.97 KB
Viewed: 12874 Time(s)

Screenshot_2022-01-04_16-20-37.png


Post 04 Jan 2022, 08:25
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 04 Jan 2022, 11:16
I think there is a bug in the redo routine. You can try the code below, but since I don't use MenuetOS, the code isn't tested and might contain bugs as well. If int 0x60 doesn't preserve r8, r9 and r10, you must add push/pop instructions in order to keep these registers.
Code:
MAG = 5         ; 500% magnification

    xor r9, r9          ; r9 = y
    xor r10, r10        ; r10 = x
    mov r8, qr_image
redo:
    mov  rcx, r9
    imul rcx, 24
    add  rcx, r10
    cmp byte [r8+rcx], 1
    jnz is_white
    mov rdx, 0x000000
    jmp show_pixel 
is_white:
    mov rdx, 0xFFFFFF
show_pixel:
    push r9
    push r10
    imul r9, MAG
    imul r10, MAG
    xor  rbx, rbx
    xor  rcx, rcx
c2:
    push rbx
    push rcx
    push rdx
    add rbx, r10        ; rbx = x
    add rcx, r9         ; rcx = y
    add rbx, 20
    add rcx, 80
    mov rax, 1
    int 0x60            ; must keep r8, r9 and r10
    pop rdx
    pop rcx
    pop rbx
    inc rbx
    cmp rbx, MAG
    jb  c2
    inc rcx
    xor rbx, rbx
    cmp rcx, MAG
    jb  c2
c1:
    pop r10
    pop r9
    inc r10
    cmp r10, 24
    jb  redo
    xor r10, r10
    inc r9
    cmp r9, 23
    jb  redo    
Post 04 Jan 2022, 11:16
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 04 Jan 2022, 19:57
Hrstka wrote:
I think there is a bug in the redo routine. You can try the code below, but since I don't use MenuetOS, the code isn't tested and might contain bugs as well.


Thank you once again, it works perfectly without modification. Now the QR code is facing upward (as you can notice the "three lines" are now at the top of the symbol.

Wonderful!

Update:

So, this project is coming to an end.
Let me list advantages and disadvantages of this small QR code generator:

Advantages:
1. Unlike competitors, this program does not have Reed-Solomon divisor polynomials, or finite field exp/log tables. Instead, if I understand correctly, it is generated during runtime. Some competitors spends hundreds of lines of code on tables of constants.
2. No other x86 Assembly of QR code generator in the market, according to my knowledge. So this is the first program of its kind that is written in x86 Assembly language.
3. Available in many desktop platforms, ranging from Windows , Linux to MenuetOS.

Disadvantages:
1. Limited to Version 1 only (21x21), Version 2 to Version 40 are not supported
2. No support for other EC level (i.e. Medium, Quartile, High)
3. No support for other mask pattern. No support for Kanji characters.


Description: QR code is now facing upward
Filesize: 114.92 KB
Viewed: 12828 Time(s)

4.jpg


Post 04 Jan 2022, 19:57
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 28 Jan 2022, 03:04
Good day everyone!

I have modified the qrcli for Linux 32-bit to display the 21x21 QR code directly in terminal window (instead of saving it as tiny BMP file).

It makes use of ANSI escape code for coloring.


Description: qrcli in terminal window
Filesize: 37.4 KB
Viewed: 12312 Time(s)

Screenshot_2022-01-28_10-58-02.png


Description:
Download
Filename: qrcli_v1.01_linux-i386.asm
Filesize: 12.54 KB
Downloaded: 458 Time(s)

Post 28 Jan 2022, 03:04
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 28 Jan 2022, 17:48
qrcode are obsolete, prefer datamatrix if really you want to barcode everything.

a proof qrcodes are obsolete, French governement use them for the sanitary pass. and when dinosaurs use something, you can be sure it's obsolete.
Post 28 Jan 2022, 17:48
View user's profile Send private message Visit poster's website Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 28 Jan 2022, 18:55
edfed wrote:
qrcode are obsolete, prefer datamatrix if really you want to barcode everything.

a proof qrcodes are obsolete, French governement use them for the sanitary pass. and when dinosaurs use something, you can be sure it's obsolete.


Thank you for introducing data matrix, I am totally new to this. Its newer version also use Reed-Solomon error correction, at least the base code probably will be unchanged. But I find it harder to encode data matrix in diagonal pattern, it says "if the tile falls off the edge, put remainder on the opposite side".
Post 28 Jan 2022, 18:55
View user's profile Send private message Reply with quote
al_Fazline



Joined: 24 Oct 2018
Posts: 54
al_Fazline 04 Feb 2022, 15:08
DataMatrix is indeed kinda easier to understand, then QR, I think.

The only problem is that I don't quite understand how to generate the error correction codes myself. It has some hardcore math in it. I'm wondering if it's using same constants as QR or not (as far as I understand particular Reed-Solomon implementation depends on several constants. I didn't find which constants DM is supposed to use however.
Post 04 Feb 2022, 15:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.