Question

Assembly Program/Language Textbook: Introduction to 64 Bit Assembly Programming for Linux and OS X, 3rd Edition,...

Assembly Program/Language

Textbook: Introduction to 64 Bit Assembly Programming for Linux and OS X, 3rd Edition, Ray Seyfarth

Chapter 7 - Exercise 1 & 2:

  1. Write an assembly program to count all the 1 bits in a byte stored in memory. Use repeated code rather than a loop.
  2. Write an assembly program to swap 2 quad-words in memory using xor. Use the following algorithm:

     a = a ^ b      b = a ^ b      a = a ^ b

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

Ans:-

Program to swap 2 quads-words in a memory using XOR:-

push rbp

mov rbp, rsp

mov DWORD PTR [rbp-20], edi

mov DWORD PTR [rbp-24], esi

mov DWORD PTR [rbp-28], edx

mov DWORD PTR [rbp-32], ecx

mov eax, DWORD PTR [rbp-24]

mov edx, DWORD PTR [rbp-20]

mov ecx, eax

shr edx, cl

mov eax, DWORD PTR [rbp-32]

mov esi, -1

mov ecx, eax

sal esi, cl

mov eax, esi

not eax

and eax, edx

mov DWORD PTR [rbp-4], eax

mov eax, DWORD PTR [rbp-28]

mov edx, DWORD PTR [rbp-20]

mov ecx, eax

shr edx, cl

mov eax, DWORD PTR [rbp-32]

mov esi, -1

mov ecx, eax

sal esi, cl

mov eax, esi

not eax

and eax, edx

mov DWORD PTR [rbp-8], eax

mov eax, DWORD PTR [rbp-4]

xor eax, DWORD PTR [rbp-8]

mov DWORD PTR [rbp-12], eax

mov eax, DWORD PTR [rbp-24]

mov edx, DWORD PTR [rbp-12]

mov ecx, eax

sal edx, cl

mov esi, edx

mov eax, DWORD PTR [rbp-28]

mov edx, DWORD PTR [rbp-12]

mov ecx, eax

sal edx, cl

mov eax, edx

or eax, esi

mov DWORD PTR [rbp-12], eax

mov eax, DWORD PTR [rbp-20]

xor eax, DWORD PTR [rbp-12]

mov DWORD PTR [rbp-16], eax

mov eax, DWORD PTR [rbp-16]

pop rbp

ret

.LC0:

.string "Result = "

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov ecx, 2

mov edx, 3

mov esi, 0

mov edi, 28

call swapBits(unsigned int, unsigned int, unsigned int, unsigned int)

mov DWORD PTR [rbp-4], eax

mov esi, OFFSET FLAT:.LC0

mov edi, OFFSET FLAT:_ZSt4cout

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

mov rdx, rax

mov eax, DWORD PTR [rbp-4]

mov esi, eax

mov rdi, rdx

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov eax, 0

leave

ret

__static_initialization_and_destruction_0(int, int):

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], edi

mov DWORD PTR [rbp-8], esi

cmp DWORD PTR [rbp-4], 1

jne .L7

cmp DWORD PTR [rbp-8], 65535

jne .L7

mov edi, OFFSET FLAT:_ZStL8__ioinit

call std::ios_base::Init::Init() [complete object constructor]

mov edx, OFFSET FLAT:__dso_handle

mov esi, OFFSET FLAT:_ZStL8__ioinit

mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev

call __cxa_atexit

.L7:

nop

leave

ret

_GLOBAL__sub_I_swapBits(unsigned int, unsigned int, unsigned int, unsigned int):

push rbp

mov rbp, rsp

mov esi, 65535

mov edi, 1

call __static_initialization_and_destruction_0(int, int)

pop rbp

ret

**program to count all 1 bits in a byte stored in memory is as follows:- Label Instruction Comments LXI H 2000H; HL points at

NOTE:- If u have any doubts please comment below and I am happily help to u brother, please thumsup bro and don't give any negative reviews please ????

Add a comment
Know the answer?
Add Answer to:
Assembly Program/Language Textbook: Introduction to 64 Bit Assembly Programming for Linux and OS X, 3rd Edition,...
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
  • Assembly Program/Language Textbook: Introduction to 64 Bit Assembly Programming for Linux and OS X, 3rd Edition,...

    Assembly Program/Language Textbook: Introduction to 64 Bit Assembly Programming for Linux and OS X, 3rd Edition, Ray Seyfarth Chapter 9 - Exercise 3: 9.3. A Pythagorean triple is a set of three integers, ?, ? and ?, such that ? 2 + ? 2 = ? 2 . Write an assembly program to print all the Pythagorean triples where ? <= 500. Use a function to test whether a number is a Pythagorean triple.

  • MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

    MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...

  • Assembly Language For x86 Processors 7th edition When you write programs to solve the programming exercises,...

    Assembly Language For x86 Processors 7th edition When you write programs to solve the programming exercises, use multiple procedures when possible. Follow the style and naming conventions used in this book. Use explanatory comments in your programs at the beginning of each procedure and next to nontrivial statements. Random Strings Create a procedure that generates a random string of length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer...

  • Consider a 64-bit computer with a simplified memory hierarchy. This hierarchy contains a single cache and...

    Consider a 64-bit computer with a simplified memory hierarchy. This hierarchy contains a single cache and an unbounded backing memory. The cache has the following characteristics: • Direct-Mapped, Write-through, Write allocate. • Cache blocks are 4 words each. • The cache has 256 sets. (a) Calculate the cache’s size in bytes. (b) Consider the following code fragment in the C programming language to be run on the described computer. Assume that: program instructions are not stored in cache, arrays are...

  • Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like...

    Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like C or Java. It does not need to run for me, but the code should be included in a text document called FirstnameLastnameHLA3.txt along with your assignment submission. Implement the program in MIPSzy Assembly language. Use the high level code as comments to the right of the Assembly code as the textbook does. If you write that MIPSzy...

  • Create a complete Assembly Language program implementation for the following application with a) 32-bit and b)...

    Create a complete Assembly Language program implementation for the following application with a) 32-bit and b) 64-bit version (If Possible) App1: Geometric Shape Calculator Companion. The program details (design, implementation, code, runs) should show evidence of technical proficiency with the following technological aspects: 1. a) Implementation using 32-bit programming. b) Re-implement using 64-bit programming. 2. Test plan; test cases implementing the test plan and screen shots displaying the executing the test cases. Note: a test plan should include various Normal,...

  • Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers

    Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • Assembly language 64 bit please ! An example file for set up ==========+ ;| Data Segment...

    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...

  • Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine...

    Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives: 1. using register indirect addressing 2. passing parameters 3. generating “random” numbers 4. working with arrays Description: Write and test a MASM program to perform the following tasks: 1. Introduce the program. 2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200....

  • *Java* Given the attached Question class and quiz text, write a driver program to input the...

    *Java* Given the attached Question class and quiz text, write a driver program to input the questions from the text file, print each quiz question, input the character for the answer, and, after all questions, report the results. Write a Quiz class for the driver, with a main method. There should be a Scanner field for the input file, a field for the array of Questions (initialized to 100 possible questions), and an int field for the actual number of...

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