Lab4
.pdf
keyboard_arrow_up
School
CUNY College of Staten Island *
*We aren’t endorsed by this school
Course
CSC-220
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
3
Uploaded by JudgeRain11219 on coursehero.com
1
Lab-4 Loops, Pointers and Stack Frame
Given the following ARM64 assembly xor.s, copy it into Raspberry Pi, then use “gcc –g –o
xor xor.s” to compile it. You should see a generated executable file “xor” in the directory.
.text
.global
main
main: sub
sp, sp,
#48
str
wzr, [sp,
44
]
mov
x0,
0x1718
movk x0,
0x1516
, lsl
16
movk x0,
0x1314
, lsl
32
movk x0,
0x1112
, lsl
48
str
x0, [sp,
8
]
mov
x0,
0x6789
movk x0,
0x2345
, lsl
16
movk x0,
0xef01
, lsl
32
movk x0,
0xabcd
, lsl
48
str
x0, [sp]
add
x0, sp,
8
str
x0, [sp,
32
]
mov
x0, sp
str
x0, [sp,
24
]
loop: ldr
w0, [sp,
44
]
cmp
w0,
7
bgt
exit
ldr
x0, [sp,
32
]
ldrb w0, [x0]
strb w0, [sp,
23
]
ldr
x0, [sp,
24
]
ldrb w0, [x0]
strb w0, [sp,
22
]
ldrb w1, [sp,
23
]
ldrb w0, [sp,
22
]
eor
w0, w1, w0
strb w0, [sp,
23
]
ldr
x0, [sp,
32
]
ldrb w1, [sp,
23
]
strb w1, [x0]
ldr
x0, [sp,
32
]
add
x0, x0,
1
str
x0, [sp,
32
]
ldr
x0, [sp,
24
]
add
x0, x0,
1
str
x0, [sp,
24
]
ldr
w0, [sp,
44
]
add
w0, w0,
1
str
w0, [sp,
44
]
b loop
exit: mov
w0,
0
add
sp, sp,
48
ret
2
Open a terminal window, single step run the program in the debugger GDB by “gdb ./xor” to
figure out what it does. Answer these questions:
1. Add commends to each line of code to tell what they do.
2. What does the initial main stack frame look like
right
after executing line-5: sub sp, sp, #48
?
3. What are the values stored in the main stack frame
before entering the loop
? Fill the
following stack frame table.
SP
+8
+16
+24
+32
+40
4. What are the values stored in the main stack frame
after the first iteration of the loop
? Fill
the following stack frame table.
SP
+8
+16
+24
+32
+40
5. What are the values stored in the main stack frame
after the second iteration of the loop
?
Fill the following stack frame table.
SP
+8
+16
+24
+32
+40
6. What are the values stored in the main stack frame
after the loop
? Fill the following stack
frame table.
SP
+8
+16
+24
+32
+40
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
In this lab, we write function binary_search in RISC-V. The prototype of the function and an implementation in C is at the end of this page.
Translate the C code at the bottom of the page to RISC-V assembly code.
The skeleton code is in lab4.s. Function binary_search is located at the end of the file. It is empty in the skeleton code.
There are some constraints/tips.
1. To ensure we do not use pseudoinstructions, we turn off the feature in RARs. In Settings, uncheck "Permit extended (pseudo)
instructions and formats".
2. Follow the C code closely. Although binary search is simple, it is very easy to make mistakes if you have not written it many times.
3. We keep variable left in register s1. Other local variables do not have to be in a saved register. Think about why we need to keep
left, but not other variables, in a saved register.
4. There should be only one exit (one return instruction) in the function. In the C code, we use goto f_exit on purpose. With one exit,
we do not have…
arrow_forward
please fill up the table shown in images with right answers
Assuming mycmd is an executable file, you type “mycmd this is cs288” and hit enter. Show the contents of memory for argc, argv, intermediate pointers, and the parameters in the memory map. Use arrows to indicate the relationship between them.
arrow_forward
a) Give an example of a one-byte instruction available in SIC/XE.
b) Give one disadvantage of hashing over binary search trees for implementing symbol tables.
c) In a load module, why is it better to have a checksum in each text record (T-record) instead of one
checksum after all the T-records?
d) What is the purpose of the super block in the Unix file system?
arrow_forward
Please write in C/C++Write a program that spawn 2 thread: a producer and a consumer
The producer thread MUST open an input file and repeatedly copy values to a CIRCULAR BUFFER
The consumer should open an output file and repeatedly copy values from the same circular buffer to the file.
If the producer is unable to write to the buffer (because it does not contain enough empty elements), or if the consumer is unable to read from the buffer (because it does not contain enough unread items), then it should proceed to the next iteration, choosing a new random number of bytes to copy.
arrow_forward
Part 1: Preliminary
Summarize the difference between binary machine language, assembly
language, and high-level source files like C.
Contrast the difference between a compiler, assembler, and linker
What is the difference between the data segment and the text segment of
in an assembly language program?
What register is used as the stack pointer?
What is a ebreak instruction in the sample program?
How would you define a constant named 'BLUE' and assign it to the value
OX00F in assembly language?
Describe how to implement the psuedo-instruction li t1, e using a
native instruction.
arrow_forward
Describe the effects on Unix data structures of using the open() function with device files. What is the behaviour of a read() system call for a device in terms of Unix data structures?
arrow_forward
To run COBOL code on z/OS, we right-click and select “Submit Job” on what file?
Select one:
a. COBOL
b. JSON
c. JCL
d. Parameters
arrow_forward
find the smallest, largest,last modified and oldest file in a directory in C language you must use opendir(), readdir() and stat() to select out the specific files matching the stated criteria. Once you have found the 4 targets, then you should list out the files in "long format" similar to what you would see if you did an "ls -l" for the specific file. Your code should also identify which criteria is being met for each output.
arrow_forward
in c++ language, make a stock management system using linked list and file handling.
( Drop code in words , explain the code and also drop the screenshot of output as well )
arrow_forward
What is the correct order for converting the source code into an executable file?
Answer Choices:
a. Preprocessing -> Compiling -> Assembly -> Linking
b. Preprocessing -> Linking -> Assembly -> Compiling
c. Compiling -> Preprocessing -> Linking -> Assembly
d. Compiling -> Preprocessing -> Assembly -> Linking
arrow_forward
. Explain the differences between stream socket and datagram socket with diagram. java
arrow_forward
Language: Python
Goal: implement decryption in the attached code block
import argparse
import os
import time
import sys
import string
# Handle command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--decrypt", help='Decrypt a file', required=False)
parser.add_argument("-e", "--encrypt", help='Encrypt a file', required=False)
parser.add_argument("-o", "--outfile", help='Output file', required=False)
args = parser.parse_args()
encrypting = True
try:
ciphertext = open(args.decrypt, "rb").read()
try:
plaintext = open(args.encrypt, "rb").read()
print("You can't specify both -e and -d")
exit(1)
except Exception:
encrypting = False
except Exception:
try:
plaintext = open(args.encrypt, "rb").read()
except Exception:
print("Input file error (did you specify -e or -d?)")
exit(1)
def lrot(n, d):
return ((n << d) & 0xff) | (n >> (8 - d))
if encrypting:
#…
arrow_forward
Object code files are generated by compilers and assemblers from source code. The object files need to be linked together before they can be executed. Compilers could, in principle, produce executables without linking. Can you explain the problems with the second method?
arrow_forward
Write a C program which takes four command line arguments: two file names and twonumber of elements. Your program must check if correct number of arguments aresupplied and terminate if not. Your main process must create three processes: The firstand second processes must open / create files by the given names and fill them with thegiven number of random integers (one integer per line) and terminate. The thirdprocess must execute “sort” command with necessary arguments so that it numericallysorts both files and display the combined result on screen.Before creating the third child process, main process must wait for the other two child processes to end.
arrow_forward
Assembly Language x86: (Micro Macro):
templet: .386.model flat, stdcall.stack 4096ExitProcess PROTO, dwExitCode: DWORD.data
.codemain PROC
main ENDPINVOKE ExitProcess, 0END main
Question: What are the reults (in decimal) of the following operations?
A: 1111001000101111 multiplied by 0000001011010010 (these are signed numbers)
B: 01011110110101101010010100101001 devided by 1111111111011010 (these are signed number)(hint: use idiv (signed), div (unsigned) )
Examples: Multiply:
mul bx, 10000 mov ax, 355 mul bx, shl edx, 16 mov dx, ax Division:mov eax, 2000000 mov bx, 500mov edx, eax
shr edx, 16 div bx,
arrow_forward
What is the maximum file size supported if we have 12 direct blocks, 3 indirect blocks, 3 double indirect blocks, and triple indirect block, a
block size of 1024 bytes and 16-bit pointers ?
arrow_forward
Write in g++
Design and implement a simple, interactive shell program that prompts the user for a command, parses the command, and then executes it with a child process. In your solution you are required to use execv(), which means that you will have to read the PATH environment, then search each directory in the PATH for the command file name that appears on the command line.
arrow_forward
Using python, write a program that does the following:
when give a data set through a numeric file (such as a .csv file),
assuming a Gaussian data distribution, write a script that returns
skewness, kurtosis, recursive partitioning, and process capability.
arrow_forward
A compiled program can be supplied as an executable file. An executable file is a file that is ready to run. Since an executable file cannot be run, programmers prefer to supply executables rather than source code. What is this executable file and what differentiates it from the source code?
In the Python programming language, the process of source code translation is different from that in C programming, explain
arrow_forward
A binary executable file built with dynamic linking includes a call to printf(). The
memory address of printf in the code...
Cannot be known, it's a macro.
Will be only determined at execution - it can be anything.
Is recorded as a parameter for the CALL instruction.
Is always stored in a register.
Depends on the version of libc that compiler knows about.
arrow_forward
From Operating System Concepts By Gagne, Galvin, Silberschatz. 10th edition Chapter 2 Project, implementation has to be in C:
This assignment will involve designing two kernel modules:
1. Design a kernel module that creates a /proc file named /proc/jiffies that reports the current value of jiffies when the /proc/jiffies file is read, such as with the command cat /proc/jiffies. Be sure to remove /proc/jiffies when the module is removed.
2. Design a kernel module that creates a proc file named /proc/seconds that reports the number of elapsed seconds since the kernel module was loaded. This will involve using the value of jiffies as well as the HZ rate. When a user enters the command cat /proc/seconds your kernel module will report the number of seconds that have elapsed since the kernel module was first loaded. Be sure to remove /proc/seconds when the module is removed.
arrow_forward
Computer organization and assembly language
Please help me with this.
I have to write line by line what each line of codes does.
CODE IS BELOW:
.model small
.386
.stack 100h
.data
msg1 db 13, 10, "Enter any number --> ", "$"
msg2 db "Enter an operation +,- * or / --> ",13, 10, "$"
msg3 db "The Operation is --> ", "$"
msg4 db "The result is --> ", "$"
By_base dd 21
by_10 dd 10 ; 32 bits variable with initial value = 10
sp_counter db 0 ; 8 bits variable with initial value of zero
disp_number dd 0 ; 32 bits variable with initial value = 0
disp_number2 dd 0
disp_number3 dd 0
op_type db 0
last_key dd 0 ; 32 bits variable with initial value of zero
remainder db 0
.code
main proc
mov ax,@data;set up datasegment
movds,ax
mov dx,offset msg1
call display_message
callm_keyin
calloperation
mov dx,offset msg1
calldisplay_message
callm_keyin
cmpop_type, "+"
jnz short skip_plus
callop_plus
skiP_plus:
cmp op_type, "-"
jnz short skip_minus
callop_minus…
arrow_forward
how do is fix this error in vs code
crbug/1173575, non-js module files deprecated.
arrow_forward
If you have experience with a language like C, C++, or Rust, in which dynamically allocated space must be manually reclaimed, describe your experience with dangling references or memory leaks. How often do these bugs arise? How do you find them? How much effort does it take? Learn about open-source or commercial tools for finding storage bugs (Valgrind is a popular open-source example). Do such tools weaken the argument for automatic garbage collection?
arrow_forward
When do you use primitives like load linked and store conditional? 1. When cooperating threads of a parallel program need to synchronize to get proper behavior for reading and writing shared data 2. When cooperating processes on a uniprocessor need to synchronize for reading and writing shared data
arrow_forward
167.
The file organization which allows us to read records that would satisfy the join condition by using one block read is
a.
Heap file organization
b.
Sequential file organization
c.
Clustering file organization
d.
Hash file organization
arrow_forward
Explain the special relationship between while loops and file handles in Perl. What is the meaning of the empty file handle, <>?
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- In this lab, we write function binary_search in RISC-V. The prototype of the function and an implementation in C is at the end of this page. Translate the C code at the bottom of the page to RISC-V assembly code. The skeleton code is in lab4.s. Function binary_search is located at the end of the file. It is empty in the skeleton code. There are some constraints/tips. 1. To ensure we do not use pseudoinstructions, we turn off the feature in RARs. In Settings, uncheck "Permit extended (pseudo) instructions and formats". 2. Follow the C code closely. Although binary search is simple, it is very easy to make mistakes if you have not written it many times. 3. We keep variable left in register s1. Other local variables do not have to be in a saved register. Think about why we need to keep left, but not other variables, in a saved register. 4. There should be only one exit (one return instruction) in the function. In the C code, we use goto f_exit on purpose. With one exit, we do not have…arrow_forwardplease fill up the table shown in images with right answers Assuming mycmd is an executable file, you type “mycmd this is cs288” and hit enter. Show the contents of memory for argc, argv, intermediate pointers, and the parameters in the memory map. Use arrows to indicate the relationship between them.arrow_forwarda) Give an example of a one-byte instruction available in SIC/XE. b) Give one disadvantage of hashing over binary search trees for implementing symbol tables. c) In a load module, why is it better to have a checksum in each text record (T-record) instead of one checksum after all the T-records? d) What is the purpose of the super block in the Unix file system?arrow_forward
- Please write in C/C++Write a program that spawn 2 thread: a producer and a consumer The producer thread MUST open an input file and repeatedly copy values to a CIRCULAR BUFFER The consumer should open an output file and repeatedly copy values from the same circular buffer to the file. If the producer is unable to write to the buffer (because it does not contain enough empty elements), or if the consumer is unable to read from the buffer (because it does not contain enough unread items), then it should proceed to the next iteration, choosing a new random number of bytes to copy.arrow_forwardPart 1: Preliminary Summarize the difference between binary machine language, assembly language, and high-level source files like C. Contrast the difference between a compiler, assembler, and linker What is the difference between the data segment and the text segment of in an assembly language program? What register is used as the stack pointer? What is a ebreak instruction in the sample program? How would you define a constant named 'BLUE' and assign it to the value OX00F in assembly language? Describe how to implement the psuedo-instruction li t1, e using a native instruction.arrow_forwardDescribe the effects on Unix data structures of using the open() function with device files. What is the behaviour of a read() system call for a device in terms of Unix data structures?arrow_forward
- To run COBOL code on z/OS, we right-click and select “Submit Job” on what file? Select one: a. COBOL b. JSON c. JCL d. Parametersarrow_forwardfind the smallest, largest,last modified and oldest file in a directory in C language you must use opendir(), readdir() and stat() to select out the specific files matching the stated criteria. Once you have found the 4 targets, then you should list out the files in "long format" similar to what you would see if you did an "ls -l" for the specific file. Your code should also identify which criteria is being met for each output.arrow_forwardin c++ language, make a stock management system using linked list and file handling. ( Drop code in words , explain the code and also drop the screenshot of output as well )arrow_forward
- What is the correct order for converting the source code into an executable file? Answer Choices: a. Preprocessing -> Compiling -> Assembly -> Linking b. Preprocessing -> Linking -> Assembly -> Compiling c. Compiling -> Preprocessing -> Linking -> Assembly d. Compiling -> Preprocessing -> Assembly -> Linkingarrow_forward. Explain the differences between stream socket and datagram socket with diagram. javaarrow_forwardLanguage: Python Goal: implement decryption in the attached code block import argparse import os import time import sys import string # Handle command-line arguments parser = argparse.ArgumentParser() parser.add_argument("-d", "--decrypt", help='Decrypt a file', required=False) parser.add_argument("-e", "--encrypt", help='Encrypt a file', required=False) parser.add_argument("-o", "--outfile", help='Output file', required=False) args = parser.parse_args() encrypting = True try: ciphertext = open(args.decrypt, "rb").read() try: plaintext = open(args.encrypt, "rb").read() print("You can't specify both -e and -d") exit(1) except Exception: encrypting = False except Exception: try: plaintext = open(args.encrypt, "rb").read() except Exception: print("Input file error (did you specify -e or -d?)") exit(1) def lrot(n, d): return ((n << d) & 0xff) | (n >> (8 - d)) if encrypting: #…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education