Alex Larose

All generations.

linuxWed, 08 Mar 2023

Write a C callable assembler function named "count" that counts the number of times a user-entered character appears in a user-entered string. The function should take two arguments: a pointer to the string and the character to be counted. Use a stack frame and return the count in %eax. Store all data as 32-bit quantities.

.section .rodata prompt: .string "Enter a string: " prompt2: .string "Enter a character: " .section .text .globl _start .type _start, @function _start: nop nop nop nop nop nop nop nop call read_string call read_char call count call print_int call exit .type count, @function count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movl 12(%ebp), %edx movl $0, %ecx jmp loop loop: movl (%eax), %ebx cmpl %edx, %ebx jne skip addl $1, %ecx skip: addl $1, %eax

linuxFri, 17 Mar 2023

Call your file printbin.s. The C caller for this program provides a char to the assembly function printbin. It asks the user for a hex number between 0 and 0xff, converts the input from an ASCII string to a char value, passes it to printbin as an argument, and displays the returned string which should be the ASCII characters for the binary value, e.g. for entry of the hex value 0x3d, you will get the printout: “The binary format for character = is 0011 1101” You can see the function prototype for the printbin function in the calling C code. The function printbin should be C callable using a stack frame and call an assembly language subprogram “donibble” that is not required to be C callable. Avoiding the use of stack frames is one way assembly code can be more efficient than C compiler generated code. The function printbin needs to declare space in the .data section for storage of a string to be returned and return the address of that location in the %eax. While processing the bits of the input argument, keep a pointer to the string in an available register. printbin and donibble can store an ascii character 0x20, 0x30, or 0x31 in the string indirectly via that register and then increment the pointer in that register until the entire return string has been filled in. The donibble function handles one half of the char value producing the four ASCII character (0/1) for the bits in one hex digit. Printbin should call donibble twice once with each nibble to be processed in half of an available register, e.g. the %al. Donibble should scan the 4 bits of the register and move an appropriate ascii code into the string for each bit. Printbin adds the space between the two nibbles.

make printbin ./printbin

linuxTue, 07 Mar 2023

Write a C callable assembler function named "count" that counts the number of times a user-entered character appears in a user-entered string. The function should take two arguments: a pointer to the string and the character to be counted. Use a stack frame and return the count in %eax. Store all data as 32-bit quantities.

.code32 .global count count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movl 12(%ebp), %edx movl $0, %ecx movl $0, %esi loop: movl (%eax), %ebx cmpl %edx, %ebx je increment addl $4, %eax cmpl $0, (%eax) je done jmp loop increment: incl %ecx addl $4, %eax cmpl $0, (%eax) je done jmp loop done: popl %ebp ret

generate functionTue, 07 Mar 2023

Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian.” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register.

int count (char *string, char c){ int count = 0; while (*string != 0){ if (*string == c){ count += 1; } string += 1; } return count; }

translateSat, 04 Mar 2023

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

++ vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> map; for (int i = 0; i < nums.size(); i++) { int complement = target - nums[i]; if (map.count(complement) and map.find(complement)->second != i) { return vector<int> {i, map.find(complement)->second}; } map[nums[i]] = i; } return vector<int> (); }

code to explanationTue, 07 Mar 2023

Write a C callable assembler function named "count" that counts the number of times a user-entered character appears in a user-entered string. The function should take two arguments: a pointer to the string and the character to be counted. Use a stack frame and return the count in %eax. Store all data as 32-bit quantities.

The function takes two arguments: a pointer to string and the character to be counted. These arguments are passed through the stack. The function allocates the stack frame and then loops through the string and increments the count each time the character is found.

translateSat, 04 Mar 2023

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

++ vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> m; for (int i = 0; i < nums.size(); ++i) { m[nums[i]] = i; } for (int i = 0; i < nums.size(); ++i) { int t = target - nums[i]; if (m.count(t) && m[t] != i) { return {i, m[t]}; } } return {}; }

code to explanationTue, 18 Apr 2023

int bits[] = {4,5,6,7}; //bit zero is bits[0] void setup() { Serial.begin(9600); for(int i = 4; i<= 7; i++) { //initalize pins [4,7] pinMode(i, OUTPUT); } } void loop() { for(int i = 0; i < 10; i++) { //displaying numbers 0 to 9 /* here you will need to add logic to figure out what bits to turn on and off * refer to the table in the instructions to know what bits to turn on and off*/ /* example of turning 0 bit on : digitalWrite(bits[0], HIGH); * example of turning 0 bit off: digitalWrite(bits[0], LOW ); */ delay(500); //1/2 a second delay so that we can see the numbers changing } }

* **Explanation** - explain what your code does. * **Code** - show your code. Do not just copy and paste it. Embed the code in your markdown file. * **Example** - show the output of your code. ### Part 2: This part will be presented in the form of a paragraph. > For this part you will need to write a paragraph that explains the concept. You will need to use the terms from the rubric. > The paragraph should be between 5 and 8 sentences. ### Part 3: This part will be presented in the form of a paragraph. > For this part you will need to write a paragraph that explains the concept. You will need to use the terms from the rubric. > The paragraph should be between 5 and 8 sentences. ### Part 4: This part will be presented in the form of a paragraph. > For this part you will need to write a paragraph that explains the concept. You will need to use the terms from the rubric. > The paragraph should

generate functionFri, 17 Mar 2023

Call your file printbin.s. The C caller for this program provides a char to the assembly function printbin. It asks the user for a hex number between 0 and 0xff, converts the input from an ASCII string to a char value, passes it to printbin as an argument, and displays the returned string which should be the ASCII characters for the binary value, e.g. for entry of the hex value 0x3d, you will get the printout: “The binary format for character = is 0011 1101” You can see the function prototype for the printbin function in the calling C code. The function printbin should be C callable using a stack frame and call an assembly language subprogram “donibble” that is not required to be C callable. Avoiding the use of stack frames is one way assembly code can be more efficient than C compiler generated code. The function printbin needs to declare space in the .data section for storage of a string to be returned and return the address of that location in the %eax. While processing the bits of the input argument, keep a pointer to the string in an available register. printbin and donibble can store an ascii character 0x20, 0x30, or 0x31 in the string indirectly via that register and then increment the pointer in that register until the entire return string has been filled in. The donibble function handles one half of the char value producing the four ASCII character (0/1) for the bits in one hex digit. Printbin should call donibble twice once with each nibble to be processed in half of an available register, e.g. the %al. Donibble should scan the 4 bits of the register and move an appropriate ascii code into the string for each bit. Printbin adds the space between the two nibbles.

#include<stdio.h> #include<string.h> char *printbin(char); int main(void) { char ch, *str; printf("Enter character: "); scanf("%c", &ch); str = printbin(ch); printf("The binary format for character %c is %s\n", ch, str); return 0; }

linuxWed, 08 Mar 2023

. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register. You are given a C calling program (countc.c) in mp2/part1/ that calls the count function to count the number of times a user-entered character appeared in a user-entered string and prints the result. The C code “driver” is in countc.c. Create a new file with the name count.s and put your

#### 1.2: linux bash command that: change directory to "test"

testsFri, 17 Mar 2023

.section .data output_string: .space 10 # allocate space for the output string .section .text .globl printbin printbin: pushl %ebp # set up the stack frame movl %esp, %ebp movl 8(%ebp), %eax # get the input character from the C program movl output_string, %ecx # set up a pointer to the output string # call donibble to process the high nibble movb %al, %ah shr $4, %ah call donibble # add a space character between the nibbles movb $0x20, (%ecx) incl %ecx # call donibble to process the low nibble movb %al, %ah and $0x0f, %ah call donibble movl output_string, %eax # return a pointer to the output string popl %ebp # restore the stack frame ret donibble: pushl %ebp # set up the stack frame movl %esp, %ebp movl 8(%ebp), %eax # get the input nibble and $0x0f, %al # mask off the high bits # convert the nibble to an ASCII character and store it in the output string add $0x30, %al movb %al, (%ecx) incl %ecx popl %ebp # restore the stack frame ret

## Source Code:

translateSat, 04 Mar 2023

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

int* twoSum(int* nums, int numsSize, int target, int* returnSize){ int *rest = (int *)malloc(sizeof(int) * 2); rest[0] = -1; rest[1] = -1; for (int i = 0; i < numsSize; i++) { for (int j = i + 1; j < numsSize; j++) { if (nums[i] + nums[j] == target) { rest[0] = i; rest[1] = j; break; } } if (rest[0] != -1) break; } *returnSize = 2; return rest; }

generate functionTue, 07 Mar 2023

Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register.

int count (char *string, char c) { int count = 0; while (*string != '\0') { if (*string == c) count++; string++; } return count; }

generate functionTue, 07 Mar 2023

Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian.” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register.

int count (char *string, char c);

generate functionTue, 07 Mar 2023

Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register.

int count (char *string, char c)

generate functionWed, 08 Mar 2023

I. OBJECTIVES: The purpose of this assignment is to gain some familiarity with writing C callable functions that use assembly language. Copy all files from /courses/cs341/s23/hefeiqiu/mp2/part1/ and /courses/cs341/s23/hefeiqiu/mp2/part2+3/ to your cs341/mp2/ directory. Use the provided makefile for all builds except where instructed otherwise. As in mp1, use the environment in users.cs.umb.edu to build all your .lnx executables and use the tutor-vserver and tutor VMs to run and debug your code. II. DESCRIPTION: Part 1: Program to count the occurrence of a user entered character in a string 1. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register. You are given a C calling program (countc.c) in mp2/part1/ that calls the count function to count the number of times a user-entered character appeared in a user-entered string and prints the result. The C code “driver” is in countc.c. Create a new file with the name count.s and put your assembly code in count.s. Then build the executable using the provided makefile by invoking “make A=count”. Capture a run of your program in the script file mp2_part1_typescript. The file is captured in the vserver VM and later transferred to your cs341/mp2/part1/ homework directory for grading. Please provide the script showing a run with a breakpoint set using either Tutor or remote gdb where the count is incremented, showing the count (in a register) each time the breakpoint is hit, just before the increment is made. In the script, show how you determined where to set the breakpoint, i.e., how you determined where the increment instruction is located in memory

#include <stdio.h> int count(char *string, char c); int main(void) { char string[100]; char c; printf("Enter a string: "); scanf("%s", string); printf("Enter a character: "); scanf(" %c", &c); printf("The character '%c' occurs %d times in \"%s\"\n", c, count(string, c), string); }

generate functionWed, 29 Mar 2023

Write a C-callable assembler version of the library strncpy function called mystrncpy (to avoid conflicts with the library version) that copies the contents of one string to a user provided array and returns a pointer to the provided array. The function prototype is: char *mystrncpy(char *s, char *ct, int n); Write your code in a source file named strncpy.s. The provided C driver (strncpyc.c) in mp2/part2+3/ takes user entered input for the source string and checks both the pointer returned and the effect of the copy. Choose test cases that exercise different possibilities in the logic of your code, e.g. a null string. What would happen if you choose a string longer than the destination array in the C driver?

public class Mystrncpy { public static void main(String[] args) { char[] s = {'a', 'b', 'c', 'd'}; char[] ct = {'e', 'f', 'g', 'h'}; int n = 3; char[] result = strncpy(s, ct, n); System.out.println("result = " + Arrays.toString(result)); } public native char[] strncpy(char[] s, char[] ct, int n); static { System.loadLibrary("strncpy"); } }

Java
View
code to explanationSat, 04 Mar 2023

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

__Questions to ask yourself__ - Does the input always have the right format? - Does the input have the right format? - Does the input have the right range? - Does the output have the right range? - Can we assume the input is valid? - Are there edge cases? - Are there some cases that we should consider separately? __Example__ Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1]. Example 2: Input: nums = [3,2,4], target = 6 Output: [1,2] Example 3: Input: nums = [3,3], target = 6 Output: [0,1] __Pseudocode__

translateTue, 07 Mar 2023

Write a C callable assembler function named "count" that counts the number of times a user-entered character appears in a user-entered string. The function should take two arguments: a pointer to the string and the character to be counted. Use a stack frame and return the count in %eax. Store all data as 32-bit quantities.

#include <stdio.h> int count(char *str, char c){ int count = 0; int index = 0; while(str[index] != '\0'){ if(str[index] == c){ count++; } index++; } return count; } int main(){ char str[100]; printf("Please input a string : "); scanf("%[^\n]", str); char c; printf("Please input a char : "); scanf(" %c", &c); int ret = count(str, c); printf("The char %c appears %d times in the string %s\n", c, ret, str); return 0; }

generate functionTue, 07 Mar 2023

Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register. You are given a C calling program (countc.c) in mp2/part1/ that calls the count function to count the number of times a user-entered character appeared in a user-entered string and prints the result. The C code “driver” is in countc.c. Create a new file with the name count.s and put your assembly code in count.s. Then build the executable using the provided makefile by invoking “make A=count”. Capture a run of your program in the script file mp2_part1_typescript. The file is captured in the vserver VM and later transferred to your cs341/mp2/part1/ homework directory for grading. Please provide the script showing a run with a breakpoint set using either Tutor or remote gdb where the count is incremented, showing the count (in a register) each time the breakpoint is hit, just before the increment is made. In the script, show how you determined where to set the breakpoint, i.e., how you determined where the increment instruction is located in memory.

#include <stdio.h> int count(char *string, char c); int main(void) { char c; char string[100]; int countval; printf("Please enter a string: "); scanf("%s", string); printf("Please enter a character: "); scanf(" %c", &c); countval = count(string, c); printf("Count = %d\n", countval); return 0; }

linuxWed, 08 Mar 2023

. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data.

int count(char*, char); int count(char* string, char c){ int i = 0; while(*(string + i) != '\0'){ if(*(string + i) == c){ break; } i++; } return i; }

linuxWed, 08 Mar 2023

. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register. You are given a C calling program (countc.c) in mp2/part1/ that calls the count function to count the number of times a user-entered character appeared in a user-entered string and prints the result. The C code “driver” is in countc.c. Create a new file with the name count.s and put your assembly code in count.s. Then build the executable using the provided makefile by invoking “make A=count”. Capture a run of your program in the script file mp2_part1_typescript. The file is captured in the vserver VM and later transferred to your cs341/mp2/part1/ homework directory for grading. Please provide the script showing a run with a breakpoint set using either Tutor or remote gdb where the count is incremented, showing the count (in a register) each time the breakpoint is hit, just before the increment is made. In the script, show how you determined where to set the breakpoint, i.e., how you determined where the increment instruction is located in memory

make A=count make run A=count make script A=count

code to explanationSat, 04 Mar 2023

int* twoSum(int* nums, int numsSize, int target, int* returnSize){ int i, j; int *result = (int*)malloc(2*sizeof(int)); for(i=0; i<numsSize; i++){ for(j=i+1; j<numsSize; j++){ if(nums[i] + nums[j] == target){ result[0] = i; result[1] = j; *returnSize = 2; return result; } } } return NULL; }

The function twoSum takes four arguments: array of integers, size of the array, target integer and pointer to size of array which will be returned. The function returns pointer to the array of two elements namely indices of the target number. First we declare pointer to the array of two elements, allocate memory for this array and set pointer to the array of two elements equal to the result. Then we loop through the array and check if the sum of the two elements is equal to the target. If yes, we return the array of two elements that stores the indices of the target number. If not, we return null.

typingsFri, 17 Mar 2023

create the assembly code printbin.s: Call your file printbin.s. The C caller for this program provides a char to the assembly function printbin. It asks the user for a hex number between 0 and 0xff, converts the input from an ASCII string to a char value, passes it to printbin as an argument, and displays the returned string which should be the ASCII characters for the binary value, e.g. for entry of the hex value 0x3d, you will get the printout: “The binary format for character = is 0011 1101” You can see the function prototype for the printbin function in the calling C code. The function printbin should be C callable using a stack frame and call an assembly language subprogram “donibble” that is not required to be C callable. Avoiding the use of stack frames is one way assembly code can be more efficient than C compiler generated code. The function printbin needs to declare space in the .data section for storage of a string to be returned and return the address of that location in the %eax. While processing the bits of the input argument, keep a pointer to the string in an available register. printbin and donibble can store an ascii character 0x20, 0x30, or 0x31 in the string indirectly via that register and then increment the pointer in that register until the entire return string has been filled in. The donibble function handles one half of the char value producing the four ASCII character (0/1) for the bits in one hex digit. Printbin should call donibble twice once with each nibble to be processed in half of an available register, e.g. the %al. Donibble should scan the 4 bits of the register and move an appropriate ascii code into the string for each bit. Printbin adds the space between the two nibbles.

#include <string.h> #include <stdio.h> extern char * printbin(unsigned char c); int main() { unsigned char c = 0x3d; printf("The binary format for character %c is %s", c, printbin(c)); }

language from codeWed, 29 Mar 2023

Write a C-callable assembler version of the library strncpy function called mystrncpy (to avoid conflicts with the library version) that copies the contents of one string to a user provided array and returns a pointer to the provided array. The function prototype is: char *mystrncpy(char *s, char *ct, int n); Write your code in a source file named strncpy.s. The provided C driver (strncpyc.c) in mp2/part2+3/ takes user entered input for the source string and checks both the pointer returned and the effect of the copy. Choose test cases that exercise different possibilities in the logic of your code, e.g. a null string. What would happen if you choose a string longer than the destination array in the C driver?

### Solution:

translateSat, 04 Mar 2023

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

int* twoSum(int* nums, int numsSize, int target, int* returnSize){ int i, j; int *result = (int*)malloc(2*sizeof(int)); for(i=0; i<numsSize; i++){ for(j=i+1; j<numsSize; j++){ if(nums[i] + nums[j] == target){ result[0] = i; result[1] = j; *returnSize = 2; return result; } } } return NULL; }

linuxWed, 08 Mar 2023

. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data.

.data str: .string "hello" char: .byte 'o' len: .long 5 .text .globl count count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movl 12(%ebp), %edx movl (%eax), %ecx movl 4(%ebp), %ebx loop: cmpl $0, %ecx je done movb (%edx), %al cmpl %al, (%ebx) je increment addl $1, %edx subl $1, %ecx jmp loop increment: addl $1, %edx addl $1, %ecx incl %eax jmp loop done: movl %ebp, %esp popl %ebp ret

translateSat, 04 Mar 2023

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

++ class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> m; int i = 0; for (auto n : nums) { if (m.find(target - n) != m.end()) { return {i, m[target - n]}; } m[n] = i++; } return {}; } };

generate functionTue, 07 Mar 2023

Write a C callable assembler function named "count" that counts the number of times a user-entered character appears in a user-entered string. The function should take two arguments: a pointer to the string and the character to be counted. Use a stack frame and return the count in %eax. Store all data as 32-bit quantities.

count: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax decl %eax movl %eax, %ebx movl 12(%ebp), %eax decl %eax movl %eax, %ecx movl $0, %edx .L3: cmpl $0, %edx je .L2 movl (%ebx), %eax pushl %eax call getchar addl $4, %esp movl %eax, %edx movl (%ecx), %eax pushl %eax call getchar addl $4, %esp cmpl %edx, %eax jne .L4 inc %edx movl $1, %eax .L4: addl $1, %ebx

code to explanationTue, 02 May 2023

/* Program to measure the pulse duration of a pulse generator. */ // Define function for Pins: int wave = 10;/* pulse generator input pin */ // the setup routine runs once when you press reset: void setup() { // initialize the digital pins pinMode(wave, INPUT); // Add a line printed to the serial monitor Serial.begin(9600); Serial.println("Hello world. Watch me measure the frequency."); } // the loop routine runs over and over again forever: void loop() { while (digitalRead(wave)) { } //skip the first positive level while (!digitalRead(wave)){ } //wait until the next positive level long count = 0; //count how many times it polls //Note: this variable is just to see how many times we poll, it shouldn't be used in calculations unsigned long start_time = micros(); //measure the current time in usec /* Your code should look something like this: * * while (wave_still_high) * increment count * read_time * while (wave_still_low) * increment count * read_time_again * * calculate the period in seconds * calculate the frequency in seconds */ //Serial.println(frequency, 5); //the second argument shows more decimal places delay(5000); //wait 5 seconds and do the test again }

## Optional Step 4. You may choose to add additional lines of code. You may also choose to add additional comments. ## Step 5. Create a new commit in Git and push it to GitHub. ## Step 6. Create a new branch in GitHub called 'lab6.3-change-file-name'. ## Step 7. In the new branch, change the file name and push it to GitHub.

translateFri, 17 Mar 2023

create the assembly code printbin.s: Call your file printbin.s. The C caller for this program provides a char to the assembly function printbin. It asks the user for a hex number between 0 and 0xff, converts the input from an ASCII string to a char value, passes it to printbin as an argument, and displays the returned string which should be the ASCII characters for the binary value, e.g. for entry of the hex value 0x3d, you will get the printout: “The binary format for character = is 0011 1101” You can see the function prototype for the printbin function in the calling C code. The function printbin should be C callable using a stack frame and call an assembly language subprogram “donibble” that is not required to be C callable. Avoiding the use of stack frames is one way assembly code can be more efficient than C compiler generated code. The function printbin needs to declare space in the .data section for storage of a string to be returned and return the address of that location in the %eax. While processing the bits of the input argument, keep a pointer to the string in an available register. printbin and donibble can store an ascii character 0x20, 0x30, or 0x31 in the string indirectly via that register and then increment the pointer in that register until the entire return string has been filled in. The donibble function handles one half of the char value producing the four ASCII character (0/1) for the bits in one hex digit. Printbin should call donibble twice once with each nibble to be processed in half of an available register, e.g. the %al. Donibble should scan the 4 bits of the register and move an appropriate ascii code into the string for each bit. Printbin adds the space between the two nibbles.

#include <stdio.h> extern void printbin(char c, char *str); int main(void) { char c, str[9]; scanf("%x", &c); printbin(c, str); printf("The binary format for character %c is %s\n", c, str); return 0; }

linuxWed, 08 Mar 2023

. Write a C callable assembler function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype: int count (char *string, char c); Since there are input arguments, your assembly function should use a stack frame. It should return the count to the calling C program in %eax. Use 32-bit quantities for all data. Even though chars have only 8 bits, they are stored in memory (and on the stack) as 32 bits in “little endian” format. If the 32-bit value is moved from memory to a register, the char value is available in the 8 least significant bits of the register. You are given a C calling program (countc.c) in mp2/part1/ that calls the count function to count the number of times a user-entered character appeared in a user-entered string and prints the result. The C code “driver” is in countc.c. Create a new file with the name count.s and put your

gcc -o countc countc.c count.s -m32

Questions about programming?Chat with your personal AI assistant