Elsewhere there are things that we all miss, yet it takes just one to notice...

Assembler PRNG (from Java to Asm)

So, I had a perfectly working PRNG in Java like this:

public class WLPRNG {
    
    long seed;
    
    public WLPRNG(long seed) { this.seed = seed; }
    
    public int nextInt() {
        long result = seed + 0x123defca;
        result = Long.rotateLeft(result, 19);
        result += 0xbead6789;
        result *= 0x1234567c;
        
        int temp = (int)result;
        
        result ^= 0x5ecdab73;
        result = Long.rotateLeft(result, 48);
        
        if (temp % 4 == 0) result *= 0x87650027;
        
        result += 13;
        seed = result;
        
        return (int)result;
    }

    public byte nextByte() {
        return (byte)nextInt();
    }
}

And I thought I’d test out the Assembler version like this:

; random number generator to be used in crypto transmission
; of sensitive data over the internet

; WLGfx 2017-Nov-19

        section .text

global  main

extern  printf

srand:  mov     [seed],rax                      ; set random seed
        ret

arand:  mov     rax,[seed]                      ; get seed
        mov     rbx,qword 0x023defca321acfed
        add     rax,rbx                         ; add 64 bit value
        rol     rax,19                          ; rotate bits
        mov     rbx,qword 0xbead6789
        add     rax,rbx                         ; another add
        imul    rax,qword 0x1234567c            ; a multiple this time
        mov     rbx,rax                         ; copy into rbx
        xor     rax,qword 0x5ecdab73            ; flip some bits
        rol     rax,48                          ; rotate bits again
        mov     rcx,rax                         ; copy to rcx
        and     rax,0x3                         ; mask and test with 0
        jnz     .notz                           ; 25% chance of other ops
        mov     rax,rbx
        add     rcx,rax
        mov     rbx,qword 0x87650027
        imul    rax,rbx
        jmp     .cont
.notz   mov     rax,rcx                         ; back into rax
.cont   mov     [seed],rax                      ; store into seed
        and     rax,0xff                        ; return byte value only
        ret

main:   mov     rax,9                           ; set seed
        call    srand

        mov     dword[lc],10                    ; set loop counter

.loop   call    arand                           ; get random byte

        push    rbp                             ; stack frame
        mov     rsi,rax                         ; random number
        mov     rdi,pf_msg                      ; format string
        xor     rax,rax                         ; 0
        call    printf                          ; call printf
        pop     rbp                             ; stack frame

        sub     dword[lc],1                     ; dec loop counter
        jnz     .loop
        
        ret

        section .data

seed    dq      0,0,0,0                         ; random seed value 64 bit
lc      dd      10                              ; loop counter

pf_msg  db      "Number: 0x%02x",10,0

Using the build script:

#!/bin/bash
nasm -f elf64 random.asm
gcc -o random random.o

Gives a sample output of:

 ~/dev/asm/tests $ ./buildrand.sh 
 ~/dev/asm/tests $ ./random 
Number: 0xe0
Number: 0x5b
Number: 0xca
Number: 0x7c
Number: 0xfc
Number: 0x2d
Number: 0x79
Number: 0xa5
Number: 0x62
Number: 0x7f

All I need to do now is to be able to link directly to C and C++ code. I’m currently reading up on threading in assembler, but it looks like the standard pthreads are just the same really.

There’s lot’s of potential for using assembler.

X86_64 printf 64 bit assembler test

So, I wanted to start playing about with assembler again. Mainly so I could use it for data encryption over the internet. Here’s a simple sample of printing 64 bit numbers as hex.

section .text
global  main

extern  printf

; use printf to print 64 bit hex string

_test:  push    rbp

        mov     rsi,0x1234567890abcdef
        mov     rdi,pf_msg
        xor     rax,rax
        call    printf

        pop     rbp
        
        ret

main:   call    _test
        
        mov     edx,len
        mov     ecx,msg
        mov     eax,4
        int     128
        
        ;mov     eax,1
        ;int     128
        
        xor     rax,rax
        ret

section .data

msg     db      "Hello world!",10
len     equ     $ - msg

; some testing stuff

pf_msg  db      "Register = %016llx", 10, 0

I set up a simple script to build the executable.

#!/bin/bash
nasm -f elf64 test.asm
gcc -o test test.o

And the output is just…

Register = 1234567890abcdef
Hello world!

The weekends plans

Yay! Friday finally came around and it’s the evening. I’m currently on a wind down, my body is aching and I’m mentally and physically zapped out. And that’s why I’m writing an update.

Over this last two weeks my website has had a few changes to it, such as https and a theme upgrade, oh and a few speedups which really did need to happen. As mentioned in an earlier blog post, there’s still a couple of minor changes that need doing, but they’re not important at the moment.

My big project I want to get back to work on over this weekend because I’ve kind of left it behind for a while. Most times when I get home from work, I just sit on my backside watching TV with my laptop. So to fix this problem, I transferred all my projects to my laptop. Win win. I already had the router set to divert a test port to this laptop anyway, so with that change in the sources, last night, everything was back up and running, 100% perfect. The mobile app has just two things to finish off, and the media manager will get a rewrite.

I have noticed that the WebGl demos only work on full screen now and not embedded in a frame since the https thingy update. If I get round to it, then I’ll look into it. Web stuff really ain’t my thing, hardcore programming is.

If I get bored over the weekend I might also create a new home hosted website using GWT or CopperLicht even. We’ll see.

Early night for me tonight because it’s been three nights on the trot of hitting the weights bench. I think the peas on my arms are growing.

Until next time.

WLGfx

This website

I’ve still got a few formatting issues with this theme which will be ironed out over time.

I’ve noticed two so far. One with images not stretching to 100% of the posts width. And the other with using the <pre> tags and the line spacing.

Apart from that, I’ll be re-organising the menus so they look a lot better and categories stuff.

I’ve added a new java page about thread pooling which I want to work on a C++ version of it over the next day or two for my personal project.

Catch y’all soon.

Not much of an update but here goes

Got many plans, and little time to get everything done. The story of my life. he he

Anyways… My journey with the ffmpeg API has now taken another turn. Now I’m travelling the realm of using the AVIOContext. This is because I need to temporarily store a UDP transport stream locally when a pause of playback is required. Before the weekend I was non the wiser of how to do this, but after a good think about it, sorted.

All I need to do is to join the multicast stream manually, grab the packets, buffer them up and when ffmpeg, via the AVIOContext requests data, just send it. Simple. One problem I’ve yet to face is that after a pause, I want to be able to seek through the saved stream. I’ll come to that.

As for my own stuff. I’m kind of halfheartedly putting my feet up. I really need to put my feet up properly actually but I’ll take what I can get.

WebGL interactive

Nothing to show yet because it would be quite dull, but I’ve got mouse movement and click interaction working in the 3D scene. Basically, if the mouse clicks an object (when it’s not occluded) it will do stuff. And when the mouse hovers over an object. Old school really, but for WebGL, this can demonstrate a lot.

And at this time of night, I’m goosed.

Another little test on water in WebGL

I’d ‘scene’ it done lots of times and I already knew that CopperLicht could do it out of the box anyway so I thought a quick 5 minutes to get something done.

I wanted to have reflective water.

View the WebGL page

Most of the time when I get home from work I am ‘goosed’ and my brain just stops for the rest of the evening. I’m hoping to change that over the next coming months.

Now that I’ve faffed about with CopperCube, it’s time to use my old Irrlicht experience and put it to some WebGL stuff using the CopperLicht 3D engine. I’ve recently purchase a level editor that allows me to create Quake 3, Half Life, etc maps. All of which can be loaded into CopperLicht and Irrlicht. With the built in collision I plan on creating a ‘maybe’ funny scene using some dodgy A.I. running around a fully light-mapped scene. I’m already looking into it.

Over the next day or two, most likely two, then again maybe longer as the mother in law is down… I want to be a bit more creative with a level design and coding. The thorn in my side is Javascript. I’ve always avoided it because I’ve considered it useless, but lately after finding that the later browsers now compile it into byte code, it’s a little more impressive.

Still don’t like it.

Press SPACE to continue…

WebGL Demos

Okay, a new page WebGL Demos has been added. So far these have just been knocked up in CopperCube using the CopperLicht WebGL 3D engine. Very easy to use and for demonstration purposes, good for eye candy shows.

 

I’ve always tried hard to stay away from HTML, CSS and Javascript because I never saw the point when I’m a programmer that can do so much more than front end web stuff.

As time goes by I will be showcasing other engines such as LibGdx and Parallax3D.

So keep your eyes peeled…

Linux shell scripts

Another thing I’ve been playing about with for the last couple of weeks is automating stuff using shell scripting.

Wow! How much time can it save you by just writing a simple script.

There’s been loads of times when I wanted to backup my project. Not only can a small script do that but it can also rename and older backup file to something else as well. By just dropping a script into a directory and run it, I’m now capable of personal version control. Okay not quite the same thing, but I know what I mean.

I’m on the verge of now being able to run scripts to automatically update software on a remote machine too using ssl. So far I can package up various pieces of software (build them if needed too) and use the scp command to copy them to a remote machine. All I need to do next is to be able to run commands and scripts over ssl. Almost there.

This shell scripting is amazingly powerful.

Qt now works with the latest Android SDK/NDK

After a short time to install 5.9.2 of Qt and then without my fingers crossed even, I loaded up Qt and loaded one of the 3D Android compatible examples.

After the first build complaining about API level 1 I fixed that and ran it again. And voila! My phone ran it. All being very slow because it was that water demo one.

Woo hoo! Might be back to Qt for desktop and mobile app dev again.

Posts navigation

1 2 3 4 5 6 7 8 9 11 12 13
Scroll to top