News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

JSON Parser

Started by iguananed, June 20, 2018, 06:43:43 AM

Previous topic - Next topic

iguananed

Just started my dabbling in MASM32 trying to determine if I will be able to develop my next application with it.

I am looking at making a High speed middle-ware application which will interface two systems using REST.

I have not found any examples of using MASM32 to parse JSON, any help would be appreciated.

Raistlin

#1
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

jj2007

Interesting link, Raistlin. Some clicks further is a SOF article on the SSE4.2 string functions. like pcmpistrm and pcmpestrm, with some surprises.

iguananed

#3
Quote from: Raistlin on June 20, 2018, 07:03:25 AMReally hard to believe you haven't seen any.
Assembly using SSE is all the rage for JSON.
see: https://amp-reddit-com.cdn.ampproject.org/v/s/amp.reddit.com/r/programming/comments/3pojrz/the_fastest_json_parser_in_the_world/?amp_js_v=a1&amp_gsa=1&usqp=mq331AQCCAE%3D#referrer=

Sorry I should have been a bit more specific. I have not seen any Source code examples or libraries.

I am looking for something like this the following but for MASM32,  https://2ton.com.au/library_as_html/json.inc.html


Raistlin

#4
Right, so that's a 64-bit library that does what you want.(link)
What's the problem then ? Not optimized ? Not enough SSE ?
AVX interesting ? The person that wrote it is not a native ASM
personage and missed a crap load of obvious cool stuff?

Now I (we, sorry guys I am being presumptive) need to know, do you have ASM expierence and want to write this? Or are you
waiting (hoping) someone has or will take up
the project ? This is sort of what it boils down
to. No effort on your part = no gain. There are
some serious weirdo SSE\AVX nuts (ppl) on
this forum. But why would they not just write the
commercial middleware themselves or consider
helping you without real effort (not copy & paste (c)).

Please understand the situation you are describing
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

iguananed

I have very little(none)  ASM experience. Just did not want to re invent the wheel. I figured it was something that might have already been done.

Raistlin

#6
Really well done young padewan.
Seriously = No, that 64-bit lib looks suspect.
I have had the privilege of seeing god-like SSE and 64-bit code in my lifetime.
Where? Right here on the forum.

The thing is, no one here will write code for you, ever... The end.
They will however painstakingly help you with your code....
ASM is the BEST, but you probably know that already.
The fastest & smallest & sexy-ist code & most difficult to unlearn in the world (probably universe) = assembly. Absolute perfection is always around the corner. Believe me, I am still hunting

BTW: We reinvent the wheel here on a daily basis. The wheels produced here, are from time to time the
subject of international peer reviewed research papers.
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

2ton

Quote from: Raistlin on June 21, 2018, 07:10:38 AM
Seriously = No, that 64-bit lib looks suspect.
Author of said lib chiming in, curious as to why you think it is suspect. (As mentioned elsewhere, it is general purpose and <= SSE2 quite intentionally, and GPL).

Cheers

Raistlin

#8
@2ton: Doubtfull.
Copy and paste original source & we might talk, (PM if you want).
What has GPL have to do with anything around the conversation. Doesn't make for better code or is that an invite?
The belief is there is sub optimum SSE instruction usage blatantly evident in the perused (prompently copyrighted) library, that no-one seemingly knew about. Until posted here that is.... suspect

My opinion is mine, asked for and answered.
If you disagree, so be it.. Find someone else to help.....
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

jj2007

Quote from: Raistlin on June 21, 2018, 08:19:27 AM
@2ton: Doubtfull. Copy and paste original source

It seems this page is indeed the original source.

2ton

Doubtful of what?

An example of using my library to deal with JSON:include 'ht/ht_defaults.inc'
include 'ht/ht.inc'

public _start
_start:
; initialise the library
call ht$init
; simple case: create a new named json object
mov rdi, .oname
call json$newobject
mov rbx, rax
mov rdi, rax
call json$tostring
mov r12, rax
mov rdi, rax
call string$to_stdoutln
mov rdi, r12
call heap$free
mov rdi, rbx
call json$destroy

; next case: parse json
mov rdi, .jtext
xor esi, esi
call json$parse_object
; turn that back into a string
mov rbx, rax
mov rdi, rax
call json$tostring
mov r12, rax
mov rdi, rax
call string$to_stdoutln
mov rdi, r12
call heap$free
mov rdi, rbx
call json$destroy

; bailout
mov eax, syscall_exit
xor edi, edi
syscall
cleartext .oname, 'ObjectName'
cleartext .jtext, '{"varone":true,"vartwo":"string","varthree":1.553,"varfour":[1,2,3,4,5,6,7,8,9],"varfive":{"subvarone":"Heya"}}'

include 'ht/ht_data.inc'


When run, it outputs "ObjectName":{}
{"varone":true,"vartwo":"string","varthree":1.553,"varfour":[1,2,3,4,5,6,7,8,9],"varfive":{"subvarone":"Heya"}}

fearless

#11
Could just use an existing json library

http://www.digip.org/jansson/
or
https://github.com/DaveGamble/cJSON
I have some precompiled libs for those in x86 and x64 with masm style includes:

- https://github.com/mrfearless/libraries/tree/master/Jansson
- https://github.com/mrfearless/libraries/tree/master/cJSON

fearless

I've updated the cjson (https://github.com/DaveGamble/cJSON) (previously libcjson v1.6.0) compiled static libraries to v1.7.12: https://github.com/mrfearless/libraries/tree/master/cJSON

Also I've moved the cjsontree x86 demo program to it's own repository: https://github.com/mrfearless/cjsontree (todo: x64 version)
Fixed a few bugs, and got it to output text based json for export and/or save using the cJSON_PrintBuffered api call. Previously I was trying to do this manually myself and it proved to be troublesome and overly complicated - for some reason I didn't see or know about the cJSON_Print api's.

2B||!2B

Nice work fearless.
Problem is i can not compile your demo.

Writing 24:1, lang:0x409, size 750.Res/cjsontreeRes.rc (50): error RC2176 : old DIB in Images/j.ico; pass it through SDKPAINT

fearless

Thats odd. What version is your resource compiler?
I'm using: Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17336
To test, I downloaded the zip of the repository and extracted to a new folder, opened the RadASM project and Make->Compile RC and it seemed to work ok.
The version of RC is the only thing that I can think of that might be the issue