Coding is one of the highest art forms achieved by mankind; an idea - just an electrical impulse - is made real in an alternate electronic universe; the created idea however, does not have physical form, and yet can change the physical world; it cannot be touched, and yet may touch all mankind.
Computer Programming Comparisons
This section deals with why we do the things we do when programming. Principles learned in class on this section apply to other aspects of what we do. Take notes!
Simulator commands (Do not type 'sim>'!):
sim> attach dsk0 cpm2.dsk sim> attach dsk1 tp3.dsk sim> set cpu 64k sim> set cpu z80 sim> set cpu nonbanked sim> set cpu altairrom sim> set cpu itrap sim> d tracks[0-7] 254 #sim> d clock 1000 if you want to slow the clock down sim> reset cpu sim> boot dsk0
When the simulator starts use MBASIC (Microsoft BASIC) from A: to enter the BASIC program below. CTRL-E will reset the simulator.
BASIC
Pre-requisite: Altair simlulator, CP/M, BASIC. This program prompts for a radius, calculates the area of a circle, asks to repeat.
10 REM This program calculates the area of a circle 20 PRINT "Enter a number: " 30 INPUT RADIUS 40 AREA = RADIUS * RADIUS * 3.14 50 PRINT "Answer: ", AREA 60 PRINT "Again? " 70 INPUT X$ 80 IF X$="Y" GOTO 20 99 END
PASCAL
Start the simulator as shown above. Change to the disk B: then start TURBO.
Pre-requisite: Altair simlulator, CP/M, Turbo Pascal. This program prompts for a radius, calculates the area of a circle.
PROGRAM circle;
VAR
radius,
area: REAL;
BEGIN
WRITELN('Enter a radius');
READLN (radius);
area := radius * radius * 3.14;
WRITELN ('Area is: ',area:3:2);
END.
Pre-requisite: Altair simlulator, CP/M, Turbo Pascal. This program prompts for a radius, calculates the area of a circle, asks to repeat.
(*
Program to calculate area of a circle
repeating until user does not indicate 'Y'
*)
PROGRAM circle;
VAR
radius,
area: REAL;
again : CHAR;
BEGIN
again := 'Y';
WHILE (again = 'Y') DO
BEGIN
WRITELN('Enter a radius');
READLN (radius);
area := radius * radius * 3.14;
WRITELN ('Area is: ',area:3:2);
WRITE ('Again? ');
READLN (again);
END;
END.
Assembly
Pre-requisite: Linux, NASM assembler. This is "Hello World" program in Linux assembly language (borrowed from elsewhere).
section .text ;section declaration
;we must export the entry point to the ELF linker or
global _start ;loader. They conventionally recognize _start as their
;entry point. Use ld -e foo to override the default.
_start:
;write our string to stdout
mov edx,len ;third argument: message length
mov ecx,msg ;second argument: pointer to message to write
mov ebx,1 ;first argument: file handle (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel - would be 0x21 in DOS
;and exit
mov ebx,0 ;first syscall argument: exit code
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data ;section declaration
msg db "Hello, world!",0xa ;our string
len equ $ - msg ;length of our string
NOTE: Ensure correct architecture. Examine final linked file size.
C
Pre-requisites: Any OS. For Linux install and use gcc C compiler. "Hello World" in C.
#include <stdio.h>
int main () {
printf ("Hello, world!\n");
}
Pre-requisites; Any OS. For Linux install and gcc C compiler. This program prompts for a radius, calculates the area of a circle, asks to repeat.
#include <stdio.h>
/* Demonstration program to show
how C looks. Calculates area of circle
aand ask to repeat. */
int main ()
{
float radius, area;
char answer, filler;
answer = 'Y';
while (answer == 'Y') {
printf ("Radius: ");
scanf ("%f", &radius);
area = radius * radius * 3.14;
printf ("Area is: %5.2f\n", area);
printf ("Again? ");
// the filler variable is use to soak up EOL character
scanf ("%c%c", &filler, &answer);
}
}
NOTE: examine binary vs source distribution.
Last updated: 20150326-11:54