Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

main.c #include \"proc.h\" int main(int argc, char *argv[]) { int x = 42; proc(x

ID: 3797553 • Letter: M

Question

main.c #include "proc.h"
int main(int argc, char *argv[]) { int x = 42;
proc(x); }
; Generated assembly code ------------------ _main: push rbp mov rbp, rsp ;—————————————————————————————————— mov dword ptr [rbp - 20], 42 mov edi, dword ptr [rbp - 20] call _proc xor eax, eax ;—————————————————————————————————— pop rbp ret

proc.c #include "proc.h" #include <stdio.h>
void proc(int val) { printf("The parameter value was %d ", val); }

; Generated assembly language —————————————————————— _proc: push rbp mov rbp, rsp ;----------------------------- mov rax, L_.str mov dword ptr [rbp - 4], edi mov esi, dword ptr [rbp - 4] mov rdi, rax mov al, 0 call _printf ;----------------------------- pop rbp ret L_.str: .asciz "The parameter value was %d "


1. explain the code marked off by the lines between the ;------ markers in the assembly language.
2. how the proc procedure found the parameter it needed to generate the message, and how that value was sent to the printf function.
main.c #include "proc.h"
int main(int argc, char *argv[]) { int x = 42;
proc(x); }
; Generated assembly code ------------------ _main: push rbp mov rbp, rsp ;—————————————————————————————————— mov dword ptr [rbp - 20], 42 mov edi, dword ptr [rbp - 20] call _proc xor eax, eax ;—————————————————————————————————— pop rbp ret

proc.c #include "proc.h" #include <stdio.h>
void proc(int val) { printf("The parameter value was %d ", val); }

; Generated assembly language —————————————————————— _proc: push rbp mov rbp, rsp ;----------------------------- mov rax, L_.str mov dword ptr [rbp - 4], edi mov esi, dword ptr [rbp - 4] mov rdi, rax mov al, 0 call _printf ;----------------------------- pop rbp ret L_.str: .asciz "The parameter value was %d "


1. explain the code marked off by the lines between the ;------ markers in the assembly language.
2. how the proc procedure found the parameter it needed to generate the message, and how that value was sent to the printf function.
main.c #include "proc.h"
int main(int argc, char *argv[]) { int x = 42;
proc(x); }
; Generated assembly code ------------------ _main: push rbp mov rbp, rsp ;—————————————————————————————————— mov dword ptr [rbp - 20], 42 mov edi, dword ptr [rbp - 20] call _proc xor eax, eax ;—————————————————————————————————— pop rbp ret #include "proc.h"
int main(int argc, char *argv[]) { int x = 42;
proc(x); }
; Generated assembly code ------------------ _main: push rbp mov rbp, rsp ;—————————————————————————————————— mov dword ptr [rbp - 20], 42 mov edi, dword ptr [rbp - 20] call _proc xor eax, eax ;—————————————————————————————————— pop rbp ret

proc.c #include "proc.h" #include <stdio.h>
void proc(int val) { printf("The parameter value was %d ", val); }

; Generated assembly language —————————————————————— _proc: push rbp mov rbp, rsp ;----------------------------- mov rax, L_.str mov dword ptr [rbp - 4], edi mov esi, dword ptr [rbp - 4] mov rdi, rax mov al, 0 call _printf ;----------------------------- pop rbp ret L_.str: .asciz "The parameter value was %d " #include "proc.h" #include <stdio.h>
void proc(int val) { printf("The parameter value was %d ", val); }

; Generated assembly language —————————————————————— _proc: push rbp mov rbp, rsp ;----------------------------- mov rax, L_.str mov dword ptr [rbp - 4], edi mov esi, dword ptr [rbp - 4] mov rdi, rax mov al, 0 call _printf ;----------------------------- pop rbp ret L_.str: .asciz "The parameter value was %d "



2. how the proc procedure found the parameter it needed to generate the message, and how that value was sent to the printf function.

Explanation / Answer

% Logistics Map % Classic chaos example. Plots semi-stable values of % x(n+1) = r*x(n)*(1-x(n)) as r increases to 4. % % Michael Hanchak, Dayton OH, USA, 2011 clear scale = 10000; % determines the level of rounding maxpoints = 200; % determines maximum values to plot N = 3000; % number of "r" values to simulate a = 2.0; % starting value of "r" b = 4; % final value of "r"... anything higher diverges. rs = linspace(a,b,N); % vector of "r" values M = 500; % number of iterations of logistics equation % Loop through the "r" values for j = 1:length(rs) r=rs(j); % get current "r" x=zeros(M,1); % allocate memory x(1) = 0.5; % initial condition (can be anything from 0 to 1) for i = 2:M, % iterate x(i) = r*x(i-1)*(1-x(i-1)); end % only save those unique, semi-stable values out{j} = unique(round(scale*x(end-maxpoints:end))); end % Rearrange cell array into a large n-by-2 vector for plotting data = []; for k = 1:length(rs) n = length(out{k}); data = [data; rs(k)*ones(n,1),out{k}]; end % Plot the data figure(97);clf h=plot(data(:,1),data(:,2)/scale,'k.'); set(h,'markersize',1) axis tight set(gca,'units','normalized','position',[0 0 1 1]) set(gcf,'color','white') axis off