cs-3843: add assignments 9 & 10
144
Fall-2024/CS-3843/Assignments/10/Assignment.typ
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
#show link: set text(blue)
|
||||||
|
#set text(font: "Calibri")
|
||||||
|
#show raw: set text(font: "Fira Code")
|
||||||
|
#set table.cell(breakable: false)
|
||||||
|
#set table(stroke: (x, y) => (
|
||||||
|
left: if x > 0 {
|
||||||
|
.1pt
|
||||||
|
},
|
||||||
|
top: if y == 1 {
|
||||||
|
0.5pt
|
||||||
|
} else if y > 1 {
|
||||||
|
0.1pt
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
|
#set page(margin: (y: .25in, x: .5in))
|
||||||
|
#let solve(solution) = {
|
||||||
|
block(
|
||||||
|
outset: 3pt,
|
||||||
|
inset: 3pt,
|
||||||
|
stroke: blue + .3pt,
|
||||||
|
fill: rgb(0, 149, 255, 15%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#solution]
|
||||||
|
}
|
||||||
|
|
||||||
|
#let solvein(solution) = {
|
||||||
|
let outset = 3pt
|
||||||
|
h(outset)
|
||||||
|
box(
|
||||||
|
outset: outset,
|
||||||
|
stroke: blue + .3pt,
|
||||||
|
fill: rgb(0, 149, 255, 15%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#solution]
|
||||||
|
}
|
||||||
|
|
||||||
|
#let note(content) = {
|
||||||
|
block(
|
||||||
|
outset: 3pt,
|
||||||
|
inset: 5pt,
|
||||||
|
stroke: luma(20%) + .3pt,
|
||||||
|
fill: luma(95%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#content]
|
||||||
|
}
|
||||||
|
|
||||||
|
#let notein(content) = {
|
||||||
|
let outset = 3pt
|
||||||
|
h(outset)
|
||||||
|
box(
|
||||||
|
outset: outset,
|
||||||
|
stroke: luma(20%) + .3pt,
|
||||||
|
fill: luma(95%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#content]
|
||||||
|
}
|
||||||
|
|
||||||
|
#align(center)[
|
||||||
|
= CS 3843 Computer Organization
|
||||||
|
HW 10\
|
||||||
|
#underline[Price Hiller] *|* #underline[zfp106]
|
||||||
|
]
|
||||||
|
#line(length: 100%, stroke: .25pt)
|
||||||
|
|
||||||
|
1. Given the 32-bit hex `0x4C4B4016`
|
||||||
|
|
||||||
|
What is the:
|
||||||
|
|
||||||
|
1. Least Significant Byte (LSB)
|
||||||
|
#solve[`0x16`]
|
||||||
|
2. Most Significant Byte (MSB)
|
||||||
|
#solve[`0x4C`]
|
||||||
|
2. Given the 32-bit hex `0x4C4B4016`, show the little-endian memory layout showing each byte in memory. Provide visualization.
|
||||||
|
#solve(
|
||||||
|
table(
|
||||||
|
columns: 2,
|
||||||
|
table.header([Byte Index], [Byte]),
|
||||||
|
[0], [`0x16`],
|
||||||
|
[1], [`0x40`],
|
||||||
|
[2], [`0x4B`],
|
||||||
|
[3], [`0x4C`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
3. If the `%rax` register is set to `0x0123456789ABCDEF`, what are the contents of the following registers in hex?
|
||||||
|
1. al
|
||||||
|
#solve[`0xEF`]
|
||||||
|
2. ax
|
||||||
|
#solve[`0xCDEF`]
|
||||||
|
3. eax
|
||||||
|
#solve[`0x89ABCDEF`]
|
||||||
|
4. rax
|
||||||
|
#solve[`0x0123456789ABCDEF`]
|
||||||
|
|
||||||
|
// #align(center + horizon, text(size: 3em, note[See Next Page]))
|
||||||
|
// #pagebreak()
|
||||||
|
|
||||||
|
4. For this value, `0xFEDCBA9876543210`, how this value will be stored in stack top location for x86-64 assembly language (hint: little-endian or big-endian). Explain and provide visualization
|
||||||
|
#solve[
|
||||||
|
#table(
|
||||||
|
align: center,
|
||||||
|
columns: (50%, 50%),
|
||||||
|
[
|
||||||
|
#underline[Little Endian]\
|
||||||
|
#solve(
|
||||||
|
table(
|
||||||
|
columns: 2,
|
||||||
|
table.header([Example Address], [Byte]),
|
||||||
|
[7], [`0xFE`],
|
||||||
|
[6], [`0xDC`],
|
||||||
|
[5], [`0xBA`],
|
||||||
|
[4], [`0x98`],
|
||||||
|
[3], [`0x76`],
|
||||||
|
[2], [`0x54`],
|
||||||
|
[1], [`0x32`],
|
||||||
|
[0], [`0x10`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
Little Endian stores the most significant byte at the at the highest memory address and the least significant byte at the lowest memory address.
|
||||||
|
],
|
||||||
|
[
|
||||||
|
#underline[Big Endian]\
|
||||||
|
#solve(
|
||||||
|
table(
|
||||||
|
columns: 2,
|
||||||
|
table.header([Example Address], [Byte]),
|
||||||
|
[7], [`0x10`],
|
||||||
|
[6], [`0x32`],
|
||||||
|
[5], [`0x54`],
|
||||||
|
[4], [`0x76`],
|
||||||
|
[3], [`0x98`],
|
||||||
|
[2], [`0xBA`],
|
||||||
|
[1], [`0xDC`],
|
||||||
|
[0], [`0xFE`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
Big Endian stores the most significant byte at the at the lowest memory address and the least significant byte at the highest memory address.
|
||||||
|
],
|
||||||
|
table.cell(colspan: 2, notein[x86-64 assembly is not _necessarily_ Little Endian. Technically it's possible for it to be Big Endian.])
|
||||||
|
)
|
||||||
|
]
|
BIN
Fall-2024/CS-3843/Assignments/10/assets/10.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/13.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/18.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/20.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/21.png
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/22.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/23.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/25.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/26.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/28.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/5.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/9-1.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/9-2.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
Fall-2024/CS-3843/Assignments/10/assets/full-prog.png
Normal file
After Width: | Height: | Size: 73 KiB |
7
Fall-2024/CS-3843/Assignments/10/registers/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "registers"
|
||||||
|
version = "0.1.0"
|
6
Fall-2024/CS-3843/Assignments/10/registers/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "registers"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
7
Fall-2024/CS-3843/Assignments/10/registers/src/main.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use std::arch::asm;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let val: u64 = 0x0123456789ABCDEF;
|
||||||
|
let eax: u32 = val as u32;
|
||||||
|
println!("{val:#0x}");
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc_fingerprint":2833596615532030163,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/nix/store/11ca83vjx4kpfnslzhgcaiihz57jmw2m-rust-nightly-complete-with-components-2024-11-15\noff\npacked\nunpacked\n___\ndebug_assertions\nfmt_debug=\"full\"\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nub_checks\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.84.0-nightly (90ab8eaed 2024-11-14)\nbinary: rustc\ncommit-hash: 90ab8eaedd3efd7919bffa7638db66e67df3f0b8\ncommit-date: 2024-11-14\nhost: x86_64-unknown-linux-gnu\nrelease: 1.84.0-nightly\nLLVM version: 19.1.3\n","stderr":""}},"successes":{}}
|
@ -0,0 +1,3 @@
|
|||||||
|
Signature: 8a477f597d28d172789f06886806bc55
|
||||||
|
# This file is a cache directory tag created by cargo.
|
||||||
|
# For information about cache directory tags see https://bford.info/cachedir/
|
@ -0,0 +1 @@
|
|||||||
|
b5dc1679863cd888
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc":7940070502224439395,"features":"[]","declared_features":"[]","target":17630001637475328777,"profile":11597332650809196192,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/registers-3ab1016305b4f322/dep-bin-registers","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
@ -0,0 +1,3 @@
|
|||||||
|
{"$message_type":"diagnostic","message":"unused import: `std::arch::asm`","code":{"code":"unused_imports","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":4,"byte_end":18,"line_start":1,"line_end":1,"column_start":5,"column_end":19,"is_primary":true,"text":[{"text":"use std::arch::asm;","highlight_start":5,"highlight_end":19}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unused_imports)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"remove the whole `use` item","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":0,"byte_end":20,"line_start":1,"line_end":2,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"use std::arch::asm;","highlight_start":1,"highlight_end":20},{"text":"","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused import: `std::arch::asm`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:1:5\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m1\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0muse std::arch::asm;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_imports)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"$message_type":"diagnostic","message":"unused variable: `eax`","code":{"code":"unused_variables","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":80,"byte_end":83,"line_start":5,"line_end":5,"column_start":9,"column_end":12,"is_primary":true,"text":[{"text":" let eax: u32 = val as u32;","highlight_start":9,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unused_variables)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"if this is intentional, prefix it with an underscore","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":80,"byte_end":83,"line_start":5,"line_end":5,"column_start":9,"column_end":12,"is_primary":true,"text":[{"text":" let eax: u32 = val as u32;","highlight_start":9,"highlight_end":12}],"label":null,"suggested_replacement":"_eax","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused variable: `eax`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:5:9\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m5\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m let eax: u32 = val as u32;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33mhelp: if this is intentional, prefix it with an underscore: `_eax`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_variables)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"$message_type":"diagnostic","message":"2 warnings emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 2 warnings emitted\u001b[0m\n\n"}
|
@ -0,0 +1 @@
|
|||||||
|
0fc2244e460ce138
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc":7940070502224439395,"features":"[]","declared_features":"[]","target":17630001637475328777,"profile":5601947868832436996,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/registers-5d9fa6fea18e1974/dep-bin-registers","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
@ -0,0 +1,3 @@
|
|||||||
|
{"$message_type":"diagnostic","message":"unused import: `std::arch::asm`","code":{"code":"unused_imports","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":4,"byte_end":18,"line_start":1,"line_end":1,"column_start":5,"column_end":19,"is_primary":true,"text":[{"text":"use std::arch::asm;","highlight_start":5,"highlight_end":19}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unused_imports)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"remove the whole `use` item","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":0,"byte_end":20,"line_start":1,"line_end":2,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"use std::arch::asm;","highlight_start":1,"highlight_end":20},{"text":"","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused import: `std::arch::asm`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:1:5\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m1\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0muse std::arch::asm;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_imports)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"$message_type":"diagnostic","message":"unused variable: `eax`","code":{"code":"unused_variables","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":80,"byte_end":83,"line_start":5,"line_end":5,"column_start":9,"column_end":12,"is_primary":true,"text":[{"text":" let eax: u32 = val as u32;","highlight_start":9,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unused_variables)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"if this is intentional, prefix it with an underscore","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":80,"byte_end":83,"line_start":5,"line_end":5,"column_start":9,"column_end":12,"is_primary":true,"text":[{"text":" let eax: u32 = val as u32;","highlight_start":9,"highlight_end":12}],"label":null,"suggested_replacement":"_eax","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused variable: `eax`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:5:9\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m5\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m let eax: u32 = val as u32;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33mhelp: if this is intentional, prefix it with an underscore: `_eax`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_variables)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"$message_type":"diagnostic","message":"2 warnings emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 2 warnings emitted\u001b[0m\n\n"}
|
@ -0,0 +1 @@
|
|||||||
|
8a6f8ecce26ae516
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc":7940070502224439395,"features":"[]","declared_features":"[]","target":17630001637475328777,"profile":5601947868832436996,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/registers-65e9c140dae6389c/dep-bin-registers","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
@ -0,0 +1,3 @@
|
|||||||
|
{"$message_type":"diagnostic","message":"unused import: `std::arch::asm`","code":{"code":"unused_imports","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":4,"byte_end":18,"line_start":1,"line_end":1,"column_start":5,"column_end":19,"is_primary":true,"text":[{"text":"use std::arch::asm;","highlight_start":5,"highlight_end":19}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unused_imports)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"remove the whole `use` item","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":0,"byte_end":20,"line_start":1,"line_end":2,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"use std::arch::asm;","highlight_start":1,"highlight_end":20},{"text":"","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused import: `std::arch::asm`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:1:5\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m1\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0muse std::arch::asm;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_imports)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"$message_type":"diagnostic","message":"unused variable: `eax`","code":{"code":"unused_variables","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":80,"byte_end":83,"line_start":5,"line_end":5,"column_start":9,"column_end":12,"is_primary":true,"text":[{"text":" let eax: u32 = val as u32;","highlight_start":9,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unused_variables)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"if this is intentional, prefix it with an underscore","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":80,"byte_end":83,"line_start":5,"line_end":5,"column_start":9,"column_end":12,"is_primary":true,"text":[{"text":" let eax: u32 = val as u32;","highlight_start":9,"highlight_end":12}],"label":null,"suggested_replacement":"_eax","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused variable: `eax`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:5:9\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m5\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m let eax: u32 = val as u32;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33mhelp: if this is intentional, prefix it with an underscore: `_eax`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_variables)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"$message_type":"diagnostic","message":"2 warnings emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 2 warnings emitted\u001b[0m\n\n"}
|
@ -0,0 +1 @@
|
|||||||
|
1b27e06e0c197588
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc":7940070502224439395,"features":"[]","declared_features":"[]","target":17630001637475328777,"profile":11983525691607113661,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/registers-a2faa7a6383c0439/dep-test-bin-registers","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
|||||||
|
e0fb7959e414329d
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc":7940070502224439395,"features":"[]","declared_features":"[]","target":17630001637475328777,"profile":15632368228915330634,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/registers-a5769e160b175648/dep-test-bin-registers","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
|||||||
|
6e2e0c501af9653a
|
@ -0,0 +1 @@
|
|||||||
|
{"rustc":7940070502224439395,"features":"[]","declared_features":"[]","target":17630001637475328777,"profile":11983525691607113661,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/registers-a8e5936099d64b0f/dep-test-bin-registers","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1,5 @@
|
|||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/registers-3ab1016305b4f322: src/main.rs
|
||||||
|
|
||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/registers-3ab1016305b4f322.d: src/main.rs
|
||||||
|
|
||||||
|
src/main.rs:
|
@ -0,0 +1,9 @@
|
|||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/libregisters-5d9fa6fea18e1974.rmeta: src/main.rs Cargo.toml
|
||||||
|
|
||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/registers-5d9fa6fea18e1974.d: src/main.rs Cargo.toml
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
Cargo.toml:
|
||||||
|
|
||||||
|
# env-dep:CLIPPY_ARGS=
|
||||||
|
# env-dep:CLIPPY_CONF_DIR
|
@ -0,0 +1,9 @@
|
|||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/libregisters-a2faa7a6383c0439.rmeta: src/main.rs Cargo.toml
|
||||||
|
|
||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/registers-a2faa7a6383c0439.d: src/main.rs Cargo.toml
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
Cargo.toml:
|
||||||
|
|
||||||
|
# env-dep:CLIPPY_ARGS=
|
||||||
|
# env-dep:CLIPPY_CONF_DIR
|
@ -0,0 +1,5 @@
|
|||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/registers-a5769e160b175648: src/main.rs
|
||||||
|
|
||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/deps/registers-a5769e160b175648.d: src/main.rs
|
||||||
|
|
||||||
|
src/main.rs:
|
BIN
Fall-2024/CS-3843/Assignments/10/registers/target/debug/registers
Executable file
@ -0,0 +1 @@
|
|||||||
|
/home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/target/debug/registers: /home/price/Git/College/Fall-2024/CS-3843/Assignments/10/registers/src/main.rs
|
218
Fall-2024/CS-3843/Assignments/9/Assignment.typ
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
#show link: set text(blue)
|
||||||
|
#set text(font: "Calibri")
|
||||||
|
#show raw: set text(font: "Fira Code")
|
||||||
|
#set table.cell(breakable: false)
|
||||||
|
#set table(stroke: (x, y) => (
|
||||||
|
left: if x > 0 {
|
||||||
|
.1pt
|
||||||
|
},
|
||||||
|
top: if y == 1 {
|
||||||
|
0.5pt
|
||||||
|
} else if y > 1 {
|
||||||
|
0.1pt
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
|
#set page(margin: (y: .5in, x: .5in))
|
||||||
|
#let solve(solution) = {
|
||||||
|
block(
|
||||||
|
outset: 3pt,
|
||||||
|
inset: 3pt,
|
||||||
|
stroke: blue + .3pt,
|
||||||
|
fill: rgb(0, 149, 255, 15%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#solution]
|
||||||
|
}
|
||||||
|
|
||||||
|
#let solvein(solution) = {
|
||||||
|
let outset = 3pt
|
||||||
|
h(outset)
|
||||||
|
box(
|
||||||
|
outset: outset,
|
||||||
|
stroke: blue + .3pt,
|
||||||
|
fill: rgb(0, 149, 255, 15%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#solution]
|
||||||
|
}
|
||||||
|
|
||||||
|
#let note(content) = {
|
||||||
|
block(
|
||||||
|
outset: 3pt,
|
||||||
|
inset: 3pt,
|
||||||
|
stroke: luma(20%) + .3pt,
|
||||||
|
fill: luma(95%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#content]
|
||||||
|
}
|
||||||
|
|
||||||
|
#let notein(content) = {
|
||||||
|
let outset = 3pt
|
||||||
|
h(outset)
|
||||||
|
box(
|
||||||
|
outset: outset,
|
||||||
|
stroke: luma(20%) + .3pt,
|
||||||
|
fill: luma(95%),
|
||||||
|
radius: 4pt,
|
||||||
|
)[#content]
|
||||||
|
}
|
||||||
|
|
||||||
|
#align(center)[
|
||||||
|
= CS 3843 Computer Organization
|
||||||
|
HW 9\
|
||||||
|
#underline[Price Hiller] *|* #underline[zfp106]
|
||||||
|
]
|
||||||
|
#line(length: 100%, stroke: .25pt)
|
||||||
|
|
||||||
|
|
||||||
|
1. [24 points] The disassembled code for two functions `first` and `last` is shown below, along with the code for a call of `first` by function `main`:
|
||||||
|
#image("./assets/q-1-code.png")
|
||||||
|
|
||||||
|
Each of these instructions is given a label. Starting with the calling of `first(10)` by `main`, fill in the following table to trace the instruction execution through to the point where the program returns back to `main`.
|
||||||
|
|
||||||
|
#solve(
|
||||||
|
table(
|
||||||
|
column-gutter: auto,
|
||||||
|
columns: 9,
|
||||||
|
align: (left, left, left, center, center, center, center, center, left),
|
||||||
|
stroke: (x, y) => {
|
||||||
|
let out = (left: none, right: none, top: none, bottom: none)
|
||||||
|
|
||||||
|
if (y == 1) {
|
||||||
|
out.top = 1.5pt + black
|
||||||
|
} else {
|
||||||
|
if (x == 0) {
|
||||||
|
out.right = .7pt + black
|
||||||
|
} else if (x == 1) {
|
||||||
|
out.left = .7pt + black
|
||||||
|
} else {
|
||||||
|
out.left = .7pt + blue
|
||||||
|
}
|
||||||
|
out.bottom = .7pt + blue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == 3 or x == 8) {
|
||||||
|
out.left = 1.0pt + black
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == 0) {
|
||||||
|
out.left = none
|
||||||
|
}
|
||||||
|
out
|
||||||
|
|
||||||
|
},
|
||||||
|
table.header(
|
||||||
|
table.cell(
|
||||||
|
colspan: 3,
|
||||||
|
align: center,
|
||||||
|
[Instruction],
|
||||||
|
),
|
||||||
|
table.cell(
|
||||||
|
colspan: 5,
|
||||||
|
align: center,
|
||||||
|
[State values (at beginning)],
|
||||||
|
),
|
||||||
|
table.cell([]),
|
||||||
|
[Label],
|
||||||
|
[PC],
|
||||||
|
[Instruction],
|
||||||
|
[%rdi],
|
||||||
|
[%rsi],
|
||||||
|
[%rax],
|
||||||
|
[%rsp],
|
||||||
|
[\*%rsp],
|
||||||
|
[Description],
|
||||||
|
table.hline(stroke: 1.5pt),
|
||||||
|
),
|
||||||
|
|
||||||
|
[`M1`], [`0x400560`], [`callq`], [`10`], [—], [—], [`0x7fffffffe820`], [—], [Call `first(10)`],
|
||||||
|
[`F1`], [`0x400548`], [`lea`], [`10`], [—], [—], [`0x7fffffffe818`], [—], [Load `&x + 1` into `%rsi`],
|
||||||
|
[`F2`], [`0x40054c`], [`sub`], [`10`], [`11`], [—], [`0x7fffffffe818`], [—], [Decrement `%rdi` by 1],
|
||||||
|
[`F3`], [`0x400550`], [`callq`], [`9`], [`11`], [—], [`0x7fffffffe810`], [—], [Call `last(9, 11)`],
|
||||||
|
[`L1`], [`0x400540`], [`mov`], [`9`], [`11`], [—], [`0x7fffffffe808`], [—], [Copy `%rdi` $->$ `%rax`],
|
||||||
|
[`L2`], [`0x400543`], [`imul`], [`9`], [`11`], [`9`], [`0x7fffffffe808`], [—], [Multiply `rdi` × `rax`, putting `99` into `rax`],
|
||||||
|
[`L3`], [`0x400547`], [`retq`], [`9`], [`11`], [`99`], [`0x7fffffffe810`], [—], [Return to first],
|
||||||
|
[`F4`], [`0x400555`], [`repz retq`], [—], [—], [`99`], [`0x7fffffffe818`], [—], [Return to main],
|
||||||
|
[`M2`],
|
||||||
|
[`0x400565`],
|
||||||
|
[`mov`],
|
||||||
|
[—],
|
||||||
|
[—],
|
||||||
|
[`99`],
|
||||||
|
[`0x7fffffffe820`],
|
||||||
|
[—],
|
||||||
|
[Copy the calculated value from `first(10)` (stored in `%rax`) to `%rdx`],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
#pagebreak()
|
||||||
|
2. [24 points] Consider a function `P`, which generates local values, named `a0`-`a8`. It then calls function `Q` using these generated values as arguments. GCC produces the following code for the first part of `P`:
|
||||||
|
|
||||||
|
#align(left)[
|
||||||
|
#image("./assets/q-2-code.png", width: 40%)
|
||||||
|
]
|
||||||
|
|
||||||
|
#enum(
|
||||||
|
numbering: "A.",
|
||||||
|
[
|
||||||
|
Identify which local values get stored in callee-saved registers.
|
||||||
|
#solve[
|
||||||
|
Local values are stored in callee-saved registers from lines 9 to 14, those being:
|
||||||
|
#block(inset: (left: 1em, bottom: .5em))[
|
||||||
|
- `%rdi -> %rbx` (`a0`)
|
||||||
|
- `%1(rdi) -> %r15` (`a1`)
|
||||||
|
- `%2(rdi) -> %r14` (`a2`)
|
||||||
|
- `%3(rdi) -> %r13` (`a3`)
|
||||||
|
- `%4(rdi) -> %r12` (`a4`)
|
||||||
|
- `%5(rdi) -> %rbp` (`a5`)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
Identify which local values get stored on the stack.
|
||||||
|
#solve[
|
||||||
|
The first local value that is stored on the stack is `a6` via the indirection of `leaq 6(%rdi), %rax` & `movq %rax, (%rsp)`.
|
||||||
|
|
||||||
|
The second local value is `a7` via `leaq 7(%rdi), %rdx` & `movq %rdx, 8(%rsp)`.
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
Explain why the program could not store all of the local values in callee saved registers.
|
||||||
|
#solve[
|
||||||
|
There are no more callee-saved registers available. It must store the last two values on the stack as that's largely the only place to put them (unless we want to start doing some heap allocations).
|
||||||
|
]
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
#pagebreak()
|
||||||
|
|
||||||
|
3. [16 points] For a C function having the general structure:
|
||||||
|
|
||||||
|
#align(left)[
|
||||||
|
#image("./assets/q-3-code.png", height: 50%)
|
||||||
|
]
|
||||||
|
#enum(
|
||||||
|
numbering: "A.",
|
||||||
|
[
|
||||||
|
What value does `rfun` store in the callee-saved register `%rbx`?
|
||||||
|
#solve[
|
||||||
|
`rfun` stores `x` in `%rbx`, see line 3 of the assembly code.
|
||||||
|
|
||||||
|
Alternatively, we can say that `rfun` stores `%rdi` in `%rbx`.
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
Fill in the missing expressions in the C code shown above.
|
||||||
|
#solve[
|
||||||
|
#note[It's odd that we have the `movl $0, %eax` _before_ the test instructions... definitely sent me for a loop.]
|
||||||
|
```c
|
||||||
|
long rfun (unsigned long x) {
|
||||||
|
if (x == 0)
|
||||||
|
return 0;
|
||||||
|
unsigned long nx = x >> 2;
|
||||||
|
long rv = rfun(nx);
|
||||||
|
return rv + x;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
]
|
||||||
|
],
|
||||||
|
)
|
BIN
Fall-2024/CS-3843/Assignments/9/assets/q-1-code.png
Normal file
After Width: | Height: | Size: 397 KiB |
BIN
Fall-2024/CS-3843/Assignments/9/assets/q-2-code.png
Normal file
After Width: | Height: | Size: 201 KiB |
BIN
Fall-2024/CS-3843/Assignments/9/assets/q-3-code.png
Normal file
After Width: | Height: | Size: 164 KiB |