Question

In: Computer Science

Write an assembly language program code to clear and set bit 7th and 19th in a...

Write an assembly language program code to clear and set bit 7th and 19th in a 32-bit variable
called N.

Solutions

Expert Solution

Ans: Assembly Language Program in this you can set, clear and toggle any bit variable.

// C program to set, clear and toggle a bit

#include <stdio.h>

// Function to set the kth bit of n

int setBit(int n, int k)

{

    return (n | (1 << (k - 1)));

}

// Function to clear the kth bit of n

int clearBit(int n, int k)

{

    return (n & (~(1 << (k - 1))));

}

// Function to toggle the kth bit of n

int toggleBit(int n, int k)

{

    return (n ^ (1 << (k - 1)));

}

// Main Logic

int main()

{

    int n = 5, k = 1;

    printf("%d with %d-th bit Set: %d\n",

           n, k, setBit(n, k));

    printf("%d with %d-th bit Cleared: %d\n",

           n, k, clearBit(n, k));

    printf("%d with %d-th bit Toggled: %d\n",

           n, k, toggleBit(n, k));

    return 0;

}


Related Solutions

Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … what is the initialization of a, b, and d? - a b d 1 ? ? 1 2 ? ? 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8 7 5 8 13 wrong initialization - a b d 1 0 1 1 2...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
using Windows 32 bit framework , Write an assembly language program to find the second minimum...
using Windows 32 bit framework , Write an assembly language program to find the second minimum element (formally, second minimum is larger than the minimum but smaller than all the other elements in the array) of an array of size 100. Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95 dup(?) and show that your program works for the first five elements. Display the second minimum in a message box using Input output macro
Write a RARS assembly language program to solve the following: For a set of integers stored...
Write a RARS assembly language program to solve the following: For a set of integers stored in an array, calculate the sum of the positive numbers and the sum of the negative numbers, storing the results into memory. In the data segment of the program, define an array consisting of 25 integers (words) that are a mix of positive and negative values. You can select any values you wish but try to create a balance of positive and negative numbers....
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
Write hack assembly language code for eq lt gt
Write hack assembly language code for eq lt gt
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT