CMSC212: Intro to Low-Level Programming Concepts

15
CMSC212: Intro to Low-Level Programming Concepts Section 0101: 9:00am – 9:50am Section 0102: 10:00am- 10:50am Monday & Wednesdays Room 3118

description

CMSC212: Intro to Low-Level Programming Concepts. Section 0101: 9:00am – 9:50am Section 0102: 10:00am-10:50am Monday & Wednesdays Room 3118. Emacs Stuff. With Xming [emacs &] calls up a new window with emacs and returns access to command-line - PowerPoint PPT Presentation

Transcript of CMSC212: Intro to Low-Level Programming Concepts

Page 1: CMSC212: Intro to Low-Level Programming Concepts

CMSC212: Intro to Low-Level Programming Concepts

Section 0101: 9:00am – 9:50amSection 0102: 10:00am-10:50amMonday & WednesdaysRoom 3118

Page 2: CMSC212: Intro to Low-Level Programming Concepts

Emacs Stuff

•With Xming▫[emacs &] calls up a new window with

emacs and returns access to command-line▫[emacs file1 &] calls up emacs with file1

read into new window▫Note: & commonly used to put process into

background [bg] to view background processes [fg %number] to pull background process

“number” to foreground

Page 3: CMSC212: Intro to Low-Level Programming Concepts

Emacs Stuff Cont’d

•Without Xming▫[emacs], [emacs file1]

•More commands▫[Ctrl-x Ctrl-c] Exit emacs▫[Ctrl-x Ctrl-s] Save file (save often)

•Useful keybinds for cursor movement▫[Ctrl-a] Beginning of current line▫[Ctrl-e] End of current line▫[Escape-<] Front of file▫[Escape->] End of file

Page 4: CMSC212: Intro to Low-Level Programming Concepts

Emacs Editing

•Keybinds for deleting text▫[Ctrl-k] Delete to end of line▫[Ctrl-u] Delete line

•Cut/pasting▫[Ctrl-space] Mark head end of cut▫[Ctrl-w] Mark tail end of cut▫[Ctrl-y] Paste

Page 5: CMSC212: Intro to Low-Level Programming Concepts

GCC Compilation and Linking

▫File test1.c

▫#include <stdio.h>int main() {

printf("This is CMSC 212.");printf(“hello world!\n");printf(“bye world!\n");return 0;

}

Page 6: CMSC212: Intro to Low-Level Programming Concepts

GCC Compilation and Linking

•Method 1▫[gcc –c test1.c]

Creates an object file test1.o▫[gcc test1.o –o test1]

Links object file(s) and outputs executable•Method 2

▫[gcc test1.c] No intermediates, produces executable a.out

▫[gcc test1.c –o test1] No intermediates, produces executable test1

Page 7: CMSC212: Intro to Low-Level Programming Concepts

Gcc Compilation and Linking Multiple files

▫File1: questionablepractices.h

▫#ifndef _QUESTIONABLE_H_#define _QUESTIONABLE_H_#include <stdio.h>

//Prototypesvoid infiniteLoop();void infiniteStack();#endif

Page 8: CMSC212: Intro to Low-Level Programming Concepts

Gcc Compilation and Linking Multiple files

▫File2: questionablecode.c

▫#include “questionablepractices.h”void infiniteLoop(){

while(1)printf(“how to terminate?\n”);

} void infiniteStack(){

printf(“o really?\n”);infiniteStack();

}

Page 9: CMSC212: Intro to Low-Level Programming Concepts

Gcc Compilation and Linking Multiple files

▫File3: questionablemain.c

▫#include “questionablepractices.h”

int main(){infiniteLoop();//infiniteStack();return 0;

}

Page 10: CMSC212: Intro to Low-Level Programming Concepts

Gcc Compilation and Linking Multiple files•How to build this?

▫gcc questionablemain.c questionablecode.c -o question Generates executable called “question”

▫gcc –c questionablemain.c questionablecode.c Generates object files questionablemain.o

questionablecode.o▫gcc questionablemain.o questionablecode.o

-question Links the two files and creates executable

Page 11: CMSC212: Intro to Low-Level Programming Concepts

Xming emacs + compilation

•Another way to compile directly through emacs▫[Escape-x] type compile

Suggests make –k (will get into later when we use make)

For now, use the standard gcc commands•Notice the new menu titled “Compile”

Page 12: CMSC212: Intro to Low-Level Programming Concepts

More Unix commands+options

•More useful commands▫[cp –r] Copy directories recursively, i.e. all

sub-file/directories▫[man cmd] pulls up the manual and

description of options for cmd, e.g. [man cp]

Page 13: CMSC212: Intro to Low-Level Programming Concepts

Chmod• [chmod [references][operator][mode] file(s)]

• reference classes• u (user/owner), g (users who are members of file

group), o (users not in g), a (all from before, i.e. ugo)• operator

• + (add modes to reference classes)• - (remove modes from reference classes)• = (specified modes are made exact for reference

classes)• Mode

• r (read), w (write), x(execute)• X, s, t (not covered)

Page 14: CMSC212: Intro to Low-Level Programming Concepts

Chmod

•E.g.•chmod ug+rw mydir

▫Gives read/write mode to user and file group of directory mydir

Page 15: CMSC212: Intro to Low-Level Programming Concepts

Questions?