Skip to content

Instantly share code, notes, and snippets.

View nikAizuddin's full-sized avatar
⚠️
s t a t i c

Nik Mohamad Aizuddin nikAizuddin

⚠️
s t a t i c
View GitHub Profile
@nikAizuddin
nikAizuddin / asmx86_xlib_plainWin
Created September 30, 2014 09:12
Create simple window using ASMx86 with Xlib
;+------------------------------------------------------------------+
;| Create simple window using ASMx86 with Xlib |
;| --------------------------------------------- |
;| |
;| This source code demonstrates on how to create GUI using |
;| ASMx86 NASM Language with Xlib. |
;| |
;| HOW TO COMPILE |
;| ---------------- |
;| |
function [T] = test()
%Arrival Time
A = [ 2.17, 7.90, 15.00, 15.17, 15.73,...
18.74, 19.86, 22.51, 23.70, 31.06];
%Begin service
W = [0 0 0 0 0 0 0 0 0 0];
%Service Time
S = [0.10, 4.46, 3.25, 2.26, 4.12, 0.69, 0.77, 3.48, 0.26, 0.41];
@nikAizuddin
nikAizuddin / NASMx86: Allocate heap memory
Created October 12, 2014 22:58
Example using brk() system call for dynamic memory allocations
; 1 2 3 4 5 6 7
;01234567890123456789012345678901234567890123456789012345678901234567890
;=======================================================================
;+---------------------------------------------------------------------+
;| |
;| Example using brk() system call for dynamic memory allocations. |
;| |
;| DON'T CONFUSE that brk() used in C Function is different with brk() |
;| systemcall (systemcall 45 for x86 ASM). |
;| |
; 1 2 3 4 5 6 7
;01234567890123456789012345678901234567890123456789012345678901234567890
;=======================================================================
;+---------------------------------------------------------------------+
;| |
;| Example using FPU registers for floating point calculations. |
;| |
;| The purpose of this source code is to demonstrate on how to |
;| do floating-point operations using FPU registers. |
;| |
; 1 2 3 4 5 6 7
;01234567890123456789012345678901234567890123456789012345678901234567890
;=======================================================================
;+---------------------------------------------------------------------+
;| |
;| Example using FPU registers for floating point calculations. |
;| |
;| The purpose of this source code is to demonstrate on how to |
;| do floating-point operations using FPU registers. |
;| |
@nikAizuddin
nikAizuddin / Print floating-point number to stdout (NASM, for Linux)
Created October 27, 2014 12:36
Print double precision value to stdout using x86 Assembly Language (NASM Assembler for Linux).
; 1 2 3 4 5 6 7
;01234567890123456789012345678901234567890123456789012345678901234567890
;=======================================================================
;+---------------------------------------------------------------------+
;| |
;| Print floating-point number to stdout |
;| |
;| This example shows how to print double value from FPU register |
;| to stdout. |
;| |
@nikAizuddin
nikAizuddin / Example how to read "Hello World" from stdin (C, Win32)
Last active August 29, 2015 14:08
Shows how to read a string that have "space" character.
/*=====================================================================
+-------------------------------------------------------------------+
| |
| Example how to read "Hello World" from stdin |
| |
| The main problem with scanf() is it unable to read properly |
| a string that have "space" character. |
| |
| This example will show how to read a string that have "space" |
| character. |
@nikAizuddin
nikAizuddin / function_example.c
Created November 10, 2014 18:58
Example how to use function
#include <stdio.h>
#include <stdlib.h>
/********************* price_after_discount() ***********************
* Find the price of an item after the discount
*
* @argument1: price = item price.
* @argument2: discount = percentage of discount.
*
* @return: item price after discount
@nikAizuddin
nikAizuddin / How the GNU GCC compiler calculate the equation: x + ++y - x * ++x - --y
Last active August 29, 2015 14:09
x + ++y - x * ++x - --y = -5 ? or = -6 ? Why = -6 ?
How the GNU GCC compiler calculate the equation:
x + ++y - x * ++x - --y
The algorithm used when perform this computation may be different across
compilers. This program is compiled using compiler GNU GCC 4.8.3 built for
Red Hat 4.8.3-7. Tools that are used to reverse engineer or disassemble
this program are "objdump" and "GNU GDB debugger".
The program will solve the following problem:
x + ++y - x * ++x - --y
@nikAizuddin
nikAizuddin / Disassemble C z = ++x + ++x + ++x;
Last active August 29, 2015 14:09
How C execute z = ++x + ++x + ++x;
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int x = 2;
int z = 0;
z = ++x + ++x + ++x;