LOLCODE to 6502 I CAN HAS TIPE CASTZ? MAH CEE-PEE-YUU IZ 8 BITZ n00b: LDA $1337.

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Intermediate Code Generation
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
Lecture 3: Instruction Set Principles Kai Bu
INSTRUCTION SET ARCHITECTURES
CS 31003: Compilers Introduction to Phases of Compiler.
MIPS Assembly Language Programming
Macro Processor.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
COEN Expressions and Assignment
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Data Types.
MIPS Instruction Set Advantages
Basic Elements of C++ Chapter 2.
Data Types. Every program must deal with data The data is usually described as a certain type This type determines what you can do with the data and how.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Machine Instruction Characteristics
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Computer Systems Organization CS 1428 Foundations of Computer Science.
CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
LOLCODE to 6502 Compiler HOW DUZ I PUSH YR POP? MAH TABLES IZ A STACKZ LDA #$1337 ; WAT U SAY?
Lecture #5 Introduction to C++
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
ECE 456 Computer Architecture
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
Execution of an instruction
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Introduction to Programming
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
Introduction CPSC 388 Ellen Walker Hiram College.
Programming Languages
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types.
1.2 Primitive Data Types and Variables
What is a program? A sequence of steps
Language Implementation Overview John Keyser Spring 2016.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Hello world !!! ASCII representation of hello.c.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
C++ LANGUAGE MULTIPLE CHOICE QUESTION SET-3
MIPS Instruction Set Advantages
Microprocessor T. Y. B. Sc..
Compiler Construction (CS-636)
Java Primer 1: Types, Classes and Operators
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Compiler Construction
Fundamental Data Types
CSCE Fall 2013 Prof. Jennifer L. Welch.
ECEG-3202 Computer Architecture and Organization
ECEG-3202 Computer Architecture and Organization
Compiler design.
ECEG-3202 Computer Architecture and Organization
CSCE Fall 2012 Prof. Jennifer L. Welch.
COMS 361 Computer Organization
Fundamental Data Types
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

LOLCODE to 6502 I CAN HAS TIPE CASTZ? MAH CEE-PEE-YUU IZ 8 BITZ n00b: LDA $1337

Limitations 8-bit A, X, Y registers Limited range of numbers Integers: -128 to 127 (signed) Floats: 4-bit mantissa, 4-bit exponent -8x10 8 to 8x10 8

Limitations Strings – a String variable is a pointer to a location in memory that holds character data Problem; addresses are 16-bit LOLCODE has dynamic variables (change types at run time) How to handle this?

Solutions Variable is represented by 3 8-bit bytes in memory 1 st byte = variable data type 0 = undefined 1 = integer (9 = negative integer) 2 = float (10 = negative float) 3 = boolean 4 = string Values 5 – F can be used for expansion

Solutions Integers are now 17-bit (16-bit data, 1-bit sign) Sign is stored in type-flag highest bit 2 nd byte stores low 8 bits, 3 rd byte stores high 8 bits Floats are now 16bit 2 nd byte holds mantissa, 3 rd is exponents

Solutions Strings are a 16-bit address stored in 2 nd and 3 rd bytes Booleans – 2 nd and 3 rd bytes treated like an integer Zero = false, Non-zero = true

Solutions Variable type can change by simply changing its type value Involves some additional code overhead when types change for most typecasts May result in runtime conversion errors (i.e. String data is not a number, float too large/loss precision)

LOLCODE to 6502 An LOLCODE input file is opened Input is scanned for tokens, sent to parser Parser constructs a parse-tree Parse-tree is transformed into an IR-tree Compiler reads IR-tree and outputs 6502 assembly Assembler assembles assembly ;d

LOLCODE Example BTW Finds the greatest common divisor GCD of two numbers HAI HOW DUZ I gcd YR n1 AN YR n2 AN YR n3 BOTH OF BOTH SAEM 0 AN MOD OF n1 AN n3 AN BOTH SAEM 0 AN MOD OF n2 AN n3 O RLY? YA RLY food R n3 OIC FOUND YR gcd n1 n2 DIFF OF n3 AN 1 IF U SAY SO I HAS A n1 I HAS A n2 VISIBLE "First number " GIMMEH n1 VISIBLE "Second number " GIMMEH n2 VISIBLE "GCD of both is " gcd n1 n2 SMALLR OF n1 AN n2 KTHXBYE

LOLCODE Function Calling LOLCODE does not have tokens to indicate that a function is called Implied from both prefix argument notation (SUM OF x AN y, FUNC_ID a1 a2 a3) At parse time, parser cannot distinguish a variable ID from a function ID IDs must be transformed into CALLs, after parsing using a symbol table

LOLCODE “IT” Conditional structures make use of a special variable called IT to determine outcome Expression by itself will store result implicitly in IT IT can be modified explicitly IT must be type cast into appropriate type for use with conditionals

LOLCODE STDIO A 6502 machine does not have native STDIO (depends on the machine/kernel) 6502 Simulator emulates a text console All IO is memory-mapped Input -> Read from memory location Output -> Write to memory location

LOLCODE:6502 Mapping 0x0000 – 0x00FF: Zero-Page, fast memory accesses, used for temporary “registers” 0x0100 – 0x01FF: Stack, used for storing function call arguments, return address 0x0200 – 0x9FF: Variable range 0x1000 – 0x3FFF: Heap/String range 0x4000 – 0x7FFF: Program code 0x8000 – 0xDFFF: Available for expansion 0xE000 – 0xFFFF: STDIO mapped here, etc

LOLCODE IR-Tree The parse-tree created from the input is transformed into an IR-tree using several things: Expressions are broken into at most binomial equations using temporaries a = b + c / d * e becomes t1 = d * e t2 = c / t1 t3 = b + t2 a = t3

LOLCODE IR-Tree Variables are renamed into memory addresses (cat becomes 0x0200) Function definitions are treated like code, and given a label to jump to String constants are assigned a label to read from

LOLCODE Memory Accessing The only way to load data into A, X, or Y from a 16-bit memory location is to use indirect memory addressing For example, data at $1234 has value $5678 Store low byte at a zero-page location, and high byte in the next location $0020 = $34, $0021 = $12

LOLCODE Memory Accessing LDA ($0020), X Reads a memory address stored at $0020, $0021 Adds X to that memory address Fetches the data at the memory address, and stores in the accumulator

What’s next? Create a memory manager, to handle heap/variables Type conversion subroutines String manipulation/storage, ties in with the MM Code generation of all LOLCODE aspects Optimization of flow structure, reduce memory accesses, etc