Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 12 Jul 2009
Offline Last Active Sep 09 2014 07:00 AM

Topics I've Started

Step by step ARM emulator

10 June 2014 - 12:36 PM

Hello everyone,


I'm writing an ARM backend for a compiler construction course and I've been searching for an ARM emulator that lets me step through my generated code instruction by instruction showing me the values of the registers.


All the emulators and simulators I've found are aimed at running full applications and/or operating systems as fast as possible but they don't offer the features I'm looking for.


Examples of what I'm looking for:

http://courses.missouristate.edu/kenvollmar/mars/ -- An emulator for MIPS

https://github.com/atzedijkstra/ssm -- An emulator for the SSM architecture.


Does anybody know of any emulators that have the features I'm looking for?


Thanks a lot in advance for any help.

.NET IRC TCPClient read hang after 30-40 minutes

25 February 2014 - 03:47 AM

I've been trying to write an IRC bot in C# using a TCPClient. It connects and starts receiving commands, responding to the PING command with a PONG command. That's all.


However, for some reason it hangs after 30 to 40 minutes on the function to read the next line of data. I've inspected the PING and PONG messages using Wireshark and they look fine to me. The PONGs are also received by the server as I do see an ACK packet being received by my computer in Wireshark.


The weird thing is that it works absolutely fine for those 30 to 40 minutes. I suspect I'm doing something wrong with the StreamReader but after searching the web for a few days I'm stuck.


Would somebody be so kind as to look at my code? Thanks a lot in advance.

public class Bot
    private NetworkStream ns;
    private StreamReader reader;
    private StreamWriter writer;
    private Encoding enc;           // The encoding used.

    /// <summary>
    /// Initialize the bot.
    /// </summary>
    public Bot()
        enc = new UTF8Encoding();

    /// <summary>
    /// Connects the an IRC server.
    /// </summary>
    /// <param name="url">The url of the server.</param>
    /// <param name="port">The port to connect to.</param>
    /// <param name="user">The username to use.</param>
    /// <param name="nick">The nick to use.</param>
    /// <param name="realName">The users real name.</param>
    public void Connect(string url, ushort port, string user, string nick, string realName)
        TcpClient client = new TcpClient();

            client.Connect(url, port);
        catch (Exception ex)
            throw new Exception("Could not connect to endpoint.", ex);

        ns = client.GetStream();
        reader = new StreamReader(ns, enc);
        writer = new StreamWriter(ns, enc);
        writer.AutoFlush = true;

        Send("USER " + user + " 0 * :" + realName + "\r\n");
        Send("NICK " + nick + "\r\n");

    /// <summary>
    /// Processes a command.
    /// </summary>
    /// <param name="command">The command to process.</param>
    public virtual void ProcessCommand(IRCCommand command)
        if(command.Command == "PING")
            Send("PONG :" + command.Parameters[0] + "\r\n");

    /// <summary>
    /// Receives and processes a command.
    /// </summary>
    public void ReceiveAndProcess()
        string line = reader.ReadLine();

        if (!string.IsNullOrEmpty(line))
            Console.WriteLine("raw : " + line);

            IRCCommand cmd = new IRCCommand();


    /// <summary>
    /// Sends a command to the irc server.
    /// </summary>
    /// <param name="ircCommand">The command to send.</param>
    protected void Send(string ircCommand)
        Console.Write("sent: " + ircCommand);

Graphics matrices give odd render results

30 October 2013 - 02:18 PM

Hello all,


I've been fiddling around with matrices. I think I have everything it working, however, the results seem kind of strange.


No rotation:



45 degrees rotation around the z-axis.



It seems like the proportions after rotations are incorrect, is this just me or what?

I've set the FOV to 90 degrees and the aspect ratio to 1024/768 for a 1024x768 window.


Thanks in advance for any help.

Calling x64 functions assembly.

25 July 2013 - 06:09 AM

Hello everybody,
I'm writing a scripting virtual machine from which I want to directly call C/C++ functions.
To do this I have a function: void x64_InvokeStatic(NativeTypes* args, NativeTypes retType, char** stack, void* func);
- func -> Function pointer.
- stack -> A pointer to the VM's stack.
- retType -> The return type.
- args -> The argument types.
This function is written in x64 assembly.
NativeTypes is defined as:
enum class NativeTypes : char
NT_Void = 1,
NT_Int8 = 2,
NT_UInt8 = 2,
NT_Int16 = 3,
NT_UInt16 = 3,
NT_Int32 = 4,
NT_UInt32 = 4,
NT_Object = 1,
NT_Int64 = 5,
NT_UInt64 = 5
The args array is 0-terminated (example, a single int32 value: NativeTypes args[2] = { NativeTypes::NT_Int32, (NativeTypes)0}; )
The values of the NativeTypes values group the size and type (eg. NT_Int32 and NT_UInt32 have the same size and do not require seperated handling).
Working on x64 Windows, I know the arguments are passed:
rcx - first argument
rdx - second argument
r8 - third argument
r9 - fourth argument
stack - rest -> all 64 bit values.
All integer values are returned in rax.
My problem is with the values pushed on the (x64) stack, they are not passed correctly.
I suspect this has to do with my own setup of the (x64) stack but after several days of trying things I still haven't found a solution.
Does anyone have an idea about what I'm doing wrong (and possibly how to fix it)?
Thanks a lot in advance.

My x64 assembly:


; Help function to get values from the VM's stack, puts them in rax.
get_arg proc
; snipped away, does not modify the (x64) stack.
get_arg endp

; void x64_InvokeStatic(NativeTypes* args, NativeTypes retType, char** stack, void* func);
x64_InvokeStatic proc
; Reserve stack space
push rbp
sub rsp, 72

; Store values
mov [rsp+8], rsp
mov [rsp+16], r15
mov [rsp+24], r14
mov [rsp+32], r13
mov [rsp+40], r12
mov [rsp+48], r9
mov [rsp+56], r8
mov [rsp+64], rdx
mov [rsp+72], rcx
mov rbp, rsp

; Load argument array.
xor r12, r12
mov r12, [rsp+72]

; First argument  ;
mov r13b, [r12]
cmp r13b, 0
je call_func

; Load VM stack
mov r14, [rsp+56]
mov r15, [r14]

call get_arg
mov rcx, rax

; Second argument  ;
add r12, 1
mov r13b, [r12]
cmp r13b, 0
je call_func

call get_arg
mov rdx, rax

; Third argument  ;
add r12, 1
mov r13b, [r12]
cmp r13b, 0
je call_func

call get_arg
mov r8, rax

; Fourth argument  ;
add r12, 1
mov r13b, [r12]
cmp r13b, 0
je call_func

call get_arg
mov r9, rax

; Stack arguments  ;
add r12, 1
mov r13b, [r12]
cmp r13b, 0
je call_func

call get_arg
push rax
jmp push_stack

; Call function
mov rax, [rbp+48]
call rax

; Discard all pushed variables.
mov r8, rbp
mov rsp, r8

; Load return type, if void -> done.
mov r12, [rsp+64]
cmp r12, 1
je done

; Load stackpointerpointer en stackpointer.
mov r13, [rsp+56]
mov r14, [r13]

; Determine what type to return.
cmp r12, 2
je ret_int8
cmp r12, 3
je ret_int16
cmp r12, 4
je ret_int32
cmp r12, 5
je ret_int64

; No known returntype, return for now.
jmp done

; Process various return type sizes.
; - Snipped, does not modify the x64 stack -

; done, restore stack and then return.
mov r15, [rsp+16]
mov r14, [rsp+24]
mov r13, [rsp+32]
mov r12, [rsp+40]
add rsp, 72
pop rbp
x64_InvokeStatic endp



Trouble in building parser for compiler.

12 July 2013 - 05:12 PM

Hello all,
I have a question related to parsing in a compiler. I'm having troubles comming up with a proper approach to parse certain statements.
For example, take this grammar:
A:= literal | variable
B:= '+' | '-'
C_1:= A
C_2:= C, B, C
C_3:= '(', C, ')'
C = C_1 | C_2 | C_3
D:= 'return', C, ';'
example of parsable code:
return (5+a) - 3;
My question is, what approach can I best to convert these rules into functions?
My main concern is, how do I make sure that for "return 3 + 5;" the proper rules (D and C_2) are used?
After having started D, thus encountering the token '3', C_1 is also satisfactory. But then the parser encounters '+' instead of the expected ';'.
I would like to write this myself for learning purposes so parser generators like yacc/bison are a no go.
Every time I think I came up with something I end up with a function so long and ugly (and non operational) that I can't help but think I'm missing something. Does anyone have some pointers?
Thanks a lot in advance.