CMSC212: Intro to Low-Level Programming Concepts
-
Upload
devin-barlow -
Category
Documents
-
view
33 -
download
0
description
Transcript of CMSC212: Intro to Low-Level Programming Concepts
![Page 1: CMSC212: Intro to Low-Level Programming Concepts](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/1.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/11.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082711/5681304c550346895d95f94b/html5/thumbnails/15.jpg)
Questions?