assembly language
for and, or, xor in assembly, what does it do with clear, set and change bit.
please give example
Here I am writing all the parts of the question below,
In assembly language AND , OR and XOR.
AND:
AND operation can be used for clearing one or more bits.For example BL register contains 0011 1100 ,if you want to clear high-order bits to ZERO, you AND it with 0FH.
AND BL, 0FH ; This sets BL to 0000 1010
next,
AND AL, 01H ; ANDing with 0000 0001
JZ EVEN_NUMBER
Example:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ax, 8h ;getting 8 in the ax
and ax, 1 ;and ax with 1
jz evnn
mov eax, 4 ;system call number (sys_write)
mov ebx, 1 ;file descriptor (stdout)
mov ecx, odd_msg ;message to write
mov edx, len2 ;length of message
int 0x80 ;call kernel
jmp outprog
evnn:
mov ah, 09h
mov eax, 4 ;system call number (sys_write)
mov ebx, 1 ;file descriptor (stdout)
mov ecx, even_msg ;message to write
mov edx, len1 ;length of message
int 0x80 ;call kernel
outprog:
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
even_msg db 'Even Number!' ;message showing even number
len1 equ $ - even_msg
odd_msg db 'Odd Number!' ;message showing odd number
len2 equ $ - odd_msg
OR :-
The OR Instruction used for supporting by performing bitwise OR operation. The OR operator returns 1 if the matching bits are either or both will be one.else returns 0.if both bits are 0.
Operand1: 0101
Operand2: 0011
After Operation ----------------- 0111
The OR operation can be used for setting one or more bits. For example, let us assume the AL register contains 0011 1010, you need to set the four low-order bits, you can OR it with a value 0000 1111 .
OR BL, 0FH ; This sets BL to 0011 1111
Example:-
OR AL, BL
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov al, 5 ;getting 5 in the al
mov bl, 3 ;getting 3 in the bl
or al, bl ;or al and bl registers, result should be 7
add al, byte '0' ;converting decimal to ascii
mov [result], al
mov eax, 4
mov ebx, 1
mov ecx, result
mov edx, 1
int 0x80
outprog:
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .bss
result resb 1
XOR Instruction:
The XOR instruction implements the bitwise XOR operation. The XOR operation sets the resultant bit to 1, if and only if the bits from the operands are different. If the bits from the operands are same (both 0 or both 1), the resultant bit is cleared to 0.
Operand1: 0101 Operand2: 0011 After XOR -> Operand1: 0110
Ex:-(simple way)
XOR EAX, EAX
Here,coming to CLEAR ,SET and change bit.
CLEAR:
Clears a register. This instruction performs an Exclusive OR between a register and itself. This will clear all bits in the register.
Ex:-
clr r18 ; clear r18 loop: inc r18 ; increase r18 ... cpi r18, $50 ; Compare r18 to $50 brne loop
SET:-
Here,it will sets bit value to some given value.
Ex:-
CF=1 ; sets carry flag is 1.
change bit:-
It will changes the bit value to opposite value.
For example:
if bit value contains 1 , then changes to 0.
if bit value contains 0 , then changes to 1.
assembly language for and, or, xor in assembly, what does it do with clear, set and change bit. please give example
Assembly Program/Language Textbook: Introduction to 64 Bit Assembly Programming for Linux and OS X, 3rd Edition, Ray Seyfarth Chapter 7 - Exercise 1 & 2: Write an assembly program to count all the 1 bits in a byte stored in memory. Use repeated code rather than a loop. 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
Code in assembly language please
"Write an assembly 32 bit program that adds two numbers (other than 5 and 6) and stores the value to a variable called 'sum'. Also, use a block COMMENT to depict the name and description of the program, author of the program, and date."
Explain in your own words what linking and loading do? Provide an example. (Assembly Language Level)
Assembly Language 64- bit system Description: You are responsible to implement several assembly functions to perform the simple arithmetic calculations for 2 64-bit integers. These functions will use the C function signature but the main logic within this function should be inline assembly code using the ASM block similar to the assembly example shown in class. 1. long XOR ( long op1, long op2 )- xor will return the result of bit exclusive OR of op1 / op2- can use...
6. I bet you thought you were done with XOR. Nope, sorry. XOR is magical, so I'm going to force feed it to you. Feast on the magic and thank me later. a) Let us begin with two 8-bit binary strings, A and B. Assume at first A = 01001010 and B has the same value. Take A and B and XOR them together in a bitwise fashion (XOR each bit of A with each bit of B. What bit...
In 32-bit MASM assembly language, write a procedure that accelpts an offset and a lenght of an array. The procedure return the sum of every 3rd elements( beginning at the 0th elements). Example: {1,2,3,4,5,6,7,8} 1+4+7=12
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...
Write ARM assembly language instructions to change the value of r0 as follows: • set the most significant byte of r0 to one’s (i.e., 0xFF) if the least significant byte of r1 is less than 90. • complement the least significant byte of r0 if r1 is odd.
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.
Please write a program in assembly language to realize the following functions: given 100 8-bit binary Numbers stored in storage DATA1 (the specific value is unknown), calculate their MEAN value and coexist in the storage unit MEAN.