Question

1. Declare a quad-word (64 bits) variable (i.e. Label) in the DATA segment of the source code. This Labes will store an INTEGER NUMBER value entered by the user at runtime using the C scan function 2. Declare a FORMAT string for use with the C scanf0 function that will accept exactly ONE INTEGER value using the %i FORMAT SPECIFIER. 3. Declare a FORMAT string for use by the C printf) function that PROMPTS the user to enter the INTEGER value. Choose YOUR OWN prompt message text for this step. 4. Declare a FORMAT string for use with the C printfO function to display the folowing string The ORGINAL INTEGER [ %ì ] represented in HEADECİMAL notation is [ or The two format specifier placeholders will each be replaced by the INTEGER value entered by the user at runtime into the Label declared in Step 1 5. Use the PROMPT string from Step 3 with printf) to instruct the user to enter a single INTEGER value using the keyboard. After the prompt message is displayed in Step 5, call the scanf) using the FORMAT string created in Step 2. Store the input value into the Label you declared in Step 1 6. 7. When the number has been entered and stored in memory in the Label created in Step 1, use the C printf() function to display the ORIGINAL NUMBER as an INTEGER type AND ASLO as a HEXADECIMAL NUMBER by using the FORMAT string created in Step 4 AND the Label from Step 1 to provide the TWO DATA values for the %i and %X printf() FORMAT SPECİFIERS 8. REPEAT (L.e. DUPLICATE) the code instructions you created for Step S, Step 6 and Step 7for EACH of following numbers ONE at a time: 15, 37, 109, 352, 5296

Assembly language 64 bit please !

An example file for set up


==========+
;| Data Segment BEGINS Here |
;+======================================================================+

segment .data
;Code this expression: sum = num1+num2
num1 dq 0 ;left operand of the addition operation
num2 dq 0 ;right operand of the addition operation
sum dq 0 ;will hold the computed Sum value
RetVal dq 0 ;Integer value RETURNED by function calls
;can be ignored or used as determined by the programmer
;Message string prompting for the keyboard input
;Terminal ,0 makes them string values
;Format string for printf() function call
Prompt4Input_fmt db 0x0a,0x0a, "%Enter the %number: ",0
First_str db "FIRST",0
Second_str db "SECOND",0
Indent15_str db " ",0
Results_fmt db 0x0a,0x0a,\
" Sum of %i + %i = %0i",0x0a,0x0a,0k
;Format string for scanf() function call
GetInteger_fmt db "%i",0
;+======================================================================+
;| Data Segment ENDS Here |
;+======================================================================+
;+======================================================================+
;| Code Segment BEGINS Here |
;+======================================================================+
segment .text
global main ;Tell the Linker about the main() entry point
extern printf ;Reference "C" printf() function
extern scanf ;Reference "C" scanf() function
extern exit ;Reference "C" exit() function

main:
push rbp ;Save CURRENT RBP on the STACK
mov rbp, rsp ;Store the current RSP (stack pointer) register
;value in the RBP register
sub rsp, 40 ;MUST create room for at least the 4 possible
;parameters in a function call that are stored
;in dedicated registers (rcx,rdx,r8,r9).
;These stack locations are referred to as the
;'shadow stack space' occupying (32 bytes MINIMUM)
;on the program's stack at runtime.
; Save incoming registers on the stack
pushregs rbx,rsi,rdi,r10,r11,r12,r13,r14,r15
  
xor rax,rax ;Clear the RAX register to 0 before beginning
;Windows printf() register uses conventions...
;printf() akways has AT LEAST 1 PARAMATER....
; 'C' Parameter number: 1 2 3 4
; In 'C' syntax: printf("fmt string", val1,val2,val3);
;Up to 4 register parameters can be entered into registers
;using these SPECIFIC registers...
;Parm 1 2 3 4 processed from left to right
;in RCX, RDX, R8, R9 REGISTER ORDER
;Prompt for the first integer
lea rcx,[Prompt4Input_fmt] ;parameter 1 uses RCX
lea rdx,[Indent15_str] ;parameter 2 uses rdx
lea r8,[First_str] ;parameter 3 uses r8 (if needed)
call printf
;Get the FIRST number from the keyboard...
lea rcx,[GetInteger_fmt]
lea rdx,[num1] ;Label in DATA SEGMENT to receive the input
call scanf ;call the function, return value in RAX
mov qword [RetVal],rax ;save the return value
;Prompt for the second integer
lea rcx,[Prompt4Input_fmt] ;parameter 1 uses RCX
lea rdx,[Indent15_str] ;parameter 2 uses rdx
lea r8,[Second_str] ;parameter 3 uses r8 (if needed)
call printf
;Get the SECOND number from the keyboard...
lea rcx,[GetInteger_fmt]
lea rdx,[num2] ;Label in DATA SEGMENT to receive the input
call scanf ;call the function, return value in RAX
mov qword [RetVal],rax ;save the return value
;Compute the SUM of the two input values
xor rax,rax ;clear the Rax register to 0
mov rax,qword [num1] ;Load RAX with the first number
mov rax,qword [num2] ;Add the two values leaving the sum
;in RAX after the addition is completed
mov [sum],rax ;save the sum value in DATA SEGMENT memory
;Display the final results using printf()....
lea rcx,[Results_fmt] ;printf() format string Parameter 1
mov rdx,[num1] ;parameter 2 uses RDX
mov r8, [num2] ;parameter 3 uses r8
mov r9, [sum] ;parameter 4 uses r9
call printf
;Restores values of incoming registers that were saved on the stack by the pushregs macro
popregs rbx,rsi,rdi,r10,r11,r12,r13,r14,r15
add rsp,40 ;Revise stack to undo line #39
xor rcx,rcx ;0 return = success
call exit ;return control to the operating system
  
;+======================================================================+
;| Code Segment ENDS Here |
;+======================================================================+


0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code as specified in the steps is as follows:

#include <stdio.h>

/* Main starts here*/

int main(int argc, const char * argv[])

{

unsigned long long label; // 64 bit variable define in C

/* Format string for prompting user for enter an integer*/

char *strprompt="\nPlease enter the value of label: \n";

/* format string for scanning 64 bit integer in C*/

char *strscan="%llu";

/* Format string for diplay integer as is and in hexadecimal notation*/

char *strdisplay="\nThe ORIGINAL INTEGER [%08llu] represented in HEXADECIMAL notation [0x%016llx]\n";

/* calling the functions and repeating the actions*/

for (int i=1;i<=5;i++)

{

printf(strprompt);

scanf(strscan, &label);

printf(strdisplay,label, label);

}

return 0;

}

OUTPUT:

Please enter the value of label: 5 The ORIGINAL INTEGER [ee800805] represented in HEXADECIMAL notation [exe000800000080005] Please enter the value of label: 37 The ORIGINAL INTEGER [00000037] represented in HEXADECIMAL notation [exee0080008000025] Please enter the value of label: 109 The ORIGINAL INTEGER [eee00109] represented in HEXADECIMAL notation [ex00008000000086d] Please enter the value of label: 352 The ORIGINAL INTEGER [e0000352] represented in HEXADECIMAL notation [ex8008088160 Please enter the value of label: 5296 The ORIGINAL INTEGER [00085296] represented in HEXADECIMAL notation [ex00000080014be] Program ended with exit code:e

Add a comment
Know the answer?
Add Answer to:
Assembly language 64 bit please ! An example file for set up ==========+ ;| Data Segment...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) Write the following C function in Assembly. You must follow the System V 64-bit calling...

    a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. long fibonacci (long n) { if (n == 0) return 0; else if (n == 1) return 1; else return (fibonacci (n - 1) + fibonacci (n - 2)); } b) The Windows x86-64 calling convention passes function parameters in the registers RCX, RDX, R8 and R9 and returns values on register RAX. Caller saved registers are: RAX,...

  • a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T S...

    a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. Note: You cannot change the algorithm in any way so your assembly function must still be recursive. (20 points) long Catalan(long n) { long sum = 0; if (n == 0) return 1; for (int i = 0; i < n; i++) { sum += Catalan(i) * Catalan(n - i - 1); } return sum; } b) The...

  • The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1];...

    The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1]; a[1] = x; a[2] = 0xA0B1C2D3; gets(buf); printf("a[0] = 0x%x, a[2] = 0x%x, buf = %s\n", a[0], a[2], buf); } In a program containing this code, procedure foo has the following disassembled form on an x86/64 machine: 000000000040057d <foo>: 40057d: push %rbp 40057e: mov %rsp,%rbp 400581: sub $0x30,%rsp 400585: mov %edi,-0x24(%rbp) 400588: mov -0x24(%rbp),%eax 40058b: mov %eax,-0xc(%rbp) 40058e: movl $0xa0b1c2d3,-0x8(%rbp) 400595: lea -0x11(%rbp),%rax 400599:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT