Skip to main content

Posts

I wrote, with the help of  The Art of Java by Herbert Schildt and James Holmes , a custom parser that evaluates a numerical expression like: "10+32/2".  So the following is the code:   package com.soliduscode.eleanya; import java.util.logging.Handler; /** * * * @author ukaku * */ public class Parser { final int NONE =0; final int DELIMITER =1; final int VARIABLE = 2; final int NUMBER = 3; final int SYNTAX = 0; final int UNBALPARENS=1; final int NOEXP = 2; final int DIVBYZERO=3; final String EOE = "\0"; /**the expression*/ private String exp; /** expression index */ private int expIndex; /**Current token*/ private String token; /**The token type*/ private int tokenType; /** * Return the next token in the expression */ private void getToken(){ //clear values initially tokenType = NONE; token = ""; //check for endl of expression if(expIndex == exp.length()){ token = EOE; return; } //ski

Creating local variables In Assembly

Lets go over how to create local variables inside of a pure assembly source code. Much like always, you will start with a *.asm file that looks like this: source code SECTION .data SECTION .bss SECTION .text global main ;make main available to operating system(os) main: ;create the stack frame push ebp push mov ebp, esp ;destroy the stack frame mov esp, ebp pop ebp ret So, the above is the general layout of an NASM source file.  Our goal here is to create a local variable inside of the main method.  The only way to create a local variable is by using the stack.  Why?  Because we can only declare variable in storage locations and the only available storage locations are: text, bss, and data.  However, text section is only for code, so it is out of the question.  The bss and data sections are appealing, but to declare our "local" variable in these sections will defeat the purpose of these variables being local, t

Writing if statements in assembly language

Programs become more and more interesting when you have dynamic elements in them.  On such way of bringing your program to life is by adding logic.  In assembly, the task can seem dubious and awkward, but once you get a grip on the concept, it will be but second nature. So lets get started! //We want to write an equivalent program to this in assembly #include <stdio.h> int main(){ int x = 40; if( x > 10){ printf("x is greater than 10\n"); }else{ printf("x is lesser than 10\n"); } return 0; } To write this in assembly, consider the following: ;an equivalent program to this in assembly SECTION .data x: dd 40 msg1: db "x is greater than 10", 10, 0 msg2: db "x is lesser than 10", 10, 0 SECTION .text Here, all we did is create our variable x, and the respective message that we will display depending on the result of our if statement. Continually: ;an equivalent program to this in assembly SECTION .data x: dd 40 msg1: db "

NASM Assembly - Hello World

Whenever you start programming, there is usually the first program that prints the phrase "Hello world" to the screen.  Well, let us keep that tradition and write an entire assembly program that print that message to the screen. ;Our Assembly Program file SECTION .data SECTION .bss SECTION .text The preceding is the standard file format of an assembly program using the Netwide assembler, or NASM. To write something to the screen, we first need to store the value of what we want to render to the screen by declaring variables. ;Our Assembly Program file SECTION .data ourHelloMsg: db "Hello world, we are in assembly", 10, 0 ;our simple message SECTION .bss SECTION .text Next, we want to use some real world practical assembly coding to print this message to the screen.  We could simple using the Linux int80h instruction to tell the operating system to print this message (if you aren't sure what I mean by this, do not worry), however we will use the printf