Serving the Quantitative Finance Community

 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

May 23rd, 2014, 8:26 am

QuoteOriginally posted by: Traden4AlphaWhat would a prime number generator look like in your language?I haven't written the assembler yet, so this is more a POC to give a flavour of what it would look like. There are probably errors in the logic as well but through I would put it here so that you can see what it looks like. The problem is that i use 6 registers due to the lack of immediate mode in ADD function. I might change that or look at using the stack more. it gives a flavour through (and no guarentee it will work).I have tried to format it neatly, but tricky through this interface!
 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

May 23rd, 2014, 8:27 am

And just realised I didn't use prime location and used a register instead. Optmisation is possible!!!
 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

July 7th, 2014, 6:52 am

Back this after a break. I have written the first pass of the instruction set without the von Neumann architecture instruction or the Offset (I don't think I need these looking at the programme above, and for the moment are definitely medium priority). In the sample above I avoided the use of a MOV command, but on reflection decided I needed it as it made life a lot easier. This required re factoring of the instruction set a little bit to enable the right addressing to be used.To be able to hook this up, I have needed to design the I/O. This is hugely tricky. So at the moment in the depths of writing the interrupt routines. Very hard as it is writing the execution of a functional language (assembler) and moving to an OO implementation. All the time you have to be aware what level you are coding for!The really difficult bit will be to hook up some form of screen + keyboard. At the moment I think the VM will appear inside the context of a form and not run on a separate thread. Ideally I want the screen + keyboard + CPU to be threaded independently. Thoughts welcome...
 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

July 7th, 2014, 6:52 am

Back this after a break. I have written the first pass of the instruction set without the von Neumann architecture instruction or the Offset (I don't think I need these looking at the programme above, and for the moment are definitely medium priority). In the sample above I avoided the use of a MOV command, but on reflection decided I needed it as it made life a lot easier. This required re factoring of the instruction set a little bit to enable the right addressing to be used.To be able to hook this up, I have needed to design the I/O. This is hugely tricky. So at the moment in the depths of writing the interrupt routines. Very hard as it is writing the execution of a functional language (assembler) and moving to an OO implementation. All the time you have to be aware what level you are coding for!The really difficult bit will be to hook up some form of screen + keyboard. At the moment I think the VM will appear inside the context of a form and not run on a separate thread. Ideally I want the screen + keyboard + CPU to be threaded independently. Thoughts welcome...
 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

September 2nd, 2014, 3:32 pm

Still battling on this one. Keep switching between wanting to finish off the interrupt routine, trying to crack the I/O problem and building the VM cradle. Concerned that the design is getting flaky too. I haven't even started looking at the assembler yet....
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Programming Education

September 2nd, 2014, 8:41 pm

Before Linux there was its papa minix from Andrew Tanenbaum of VU, Amsterdam. QuoteThe design principles Tanenbaum applied to MINIX greatly influenced the design decisions Linus Torvalds applied in the creation of the Linux kernel. Torvalds used and appreciated MINIX, but his design deviated from the MINIX architecture in significant ways, most notably by employing a monolithic kernel instead of a microkernel. This was famously disapproved of by Tanenbaum in the Tanenbaum?Torvalds debate. Tanenbaum explained again his rationale for using a microkernel in May 2006.[10]Monolithic is not modular nor orthogonal!(?)This modularity of the operating system is at the binary (image) level and not at the architecture level.Is rmax' design mono or micro-based?
Last edited by Cuchulainn on September 1st, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

September 3rd, 2014, 7:51 pm

The problems are legion and multitude.One to bring up. How should interrupts work?All peripherals will be written in software. I don't think that the VM should have any direct access to any of the physical parts of the machine it is hosted on.So how should the interrupts be implemented?The easy bit is that in the main loop that executes the instructions, when an interrupt is raised, the processor pushes the current Program Counter location and Program Registers onto the stack. It then executes the jump that is pointed to by the interrupt.The difficult bit is that the I think the peripheral needs to request the interrupt number from the virtual machine. This would mean that the virtual machine will then look at the interrupt requests that have been assigned and then assign the next free interrupt number. This will mean that there is no messing about configuring interrupt queues.So far so good, however it now raises the following questions that I can't get my head around:1/ The process of connecting the peripheral and assigning the IRQ etc would be done outside of that virtual machine CPU. Is this "cheating"?2/ The peripheral must communicate across some kind of data bus. However the data bus needs to be of various sizes. Sending data to a screen output device needs a different band width from receiving data from a keyboard. There are a couple of ways in which this could be done. Either there is a memory location that the peripheral places data or there is a databus that somehow the CPU read from. If it is a memory location then this needs to be managed to ensure that the OS (yes that will need to be written as well!!) does not overwrite the location. If the memory is reserved and cannot be overwritten it limits the number of peripherals that can be connected. If the databus method I cannot see how to design.
 
User avatar
rmax
Topic Author
Posts: 374
Joined: December 8th, 2005, 9:31 am

Programming Education

September 4th, 2014, 11:14 am

Thanks for the post. I have avoided a virtual clock up to this point - thinking that I might be able to get away with it as I am not trying to emulate another system. After reading this I am not sure I can. At the moment the interrupt would be raised and then processed, and hence might lead to a condition of no processing possible due to holding down a key. I think I do need to write an Interrupt queue (FIFO) as the interrupts raised will be asynchronous from when they are processed.Mmm - food for thought....QuoteOriginally posted by: outrunI once wrote a realistic even simulator using a "priority queue". A priority queue is a list of {timestamp, action/event} pairs, sorted on timestamp. The action is eg a function pointer. The simulator pops the first action from the front of the queue and executes that action. It's extremely powerful, e.g. we implemented an virtual internal clock (which the simulator could use to time itself in virtual time!) by simply have an action that would insert a clock event 1 second further in the queue.before processing the clock_event():1: 0:00:20.402, clock_event()2: 0:00:20.802, do_somethingX()3: 0:00:21.356, do_somethingY()4: 0:00:21.913, do_somethingZ()after processing the clock_event():2: 0:00:20.802, do_somethingX()3: 0:00:21.356, do_somethingY()1: 0:00:21.402, clock_event() <-- newly inserted clock event4: 0:00:21.913, do_somethingZ()Another thing you can do is to measure the duration of tasks in the main event handler loop and let various hardware components run in a simulated parallel. Every task you pop of the queue get's timed, and when finished you compute the virtual time that would finish and insert a future event back into the queue (just like with the clock). After completion the next event with highest time priority in the queue might be moved to a simulated io bufferSuppose the event queue looks like this at 0:00:20.402 (virtual time)1: 0:00:20.402, draw_sceen()2: 0:00:20.800, key_press_Q()3: 0:00:20.900, key_press_W()4: 0:00:21.000, key_press_E()5: 0:00:21.100, key_press_R()6: 0:00:21.200, key_press_T()7: 0:00:21.300, key_press_Y()..now suppose you measure with a real clock that draw_screen takes 0.5 seconds. You could insert a draw_complete() event at 0:00:20.902 into the queue which might pop the instruction pointer. You will then know that you first have to process the Q and W keypress events (move then to a keyboard buffer?) before you can pop the instruction pointer from the stack.
 
User avatar
Traden4Alpha
Posts: 3300
Joined: September 20th, 2002, 8:30 pm

Programming Education

September 4th, 2014, 12:00 pm

Your interrupt system need not be complex unless you are trying to simulate a complex, high-performance, highly-responsive system. In a very simple computer, holding down a key counts as only one key press and attempting to flood the computer with a high rate of key presses simply results in those extra presses being lost.You might simplify your system with a simulation of a UART as the mediator between the CPU and various interrupt-driven, asynchronous I/O subsystems (keyboard, mouse, secondary storage system, network I/O).
 
User avatar
tags
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

Programming Education

September 14th, 2014, 7:53 am

codility