MASM (Assembly programming) This question is not from a textbook, but the textbo
ID: 662393 • Letter: M
Question
MASM (Assembly programming)
This question is not from a textbook, but the textbook used during course:
Assembly Language for x86 Processors, 6th Edition, by Irvine
--
Question:
Using bit-wise Boolean operations (AND, OR, XOR, NOT, TEST), and NO arithmetic operations (ADD, SUB, MUL, NEG, CMP, ...), write a program that receives a signed number in the AX register, and alters this (returning answer in AX) as follows using ONLY four bit-wise Boolean operations:
1. If the number is negative, say -n, then replace it with the non-negative number n-1, and then
2. If the number is divisible by 8, then add 6 to it, and then
3. If it is even, add one to it, but if it is odd, subtract one from it.
Explanation / Answer
leaq -4(%rbp), %rax movq %rax, %rsi movl $_ZSt3cin, %edi .LEHB0: call _ZNSirsERi .LEHE0: movl -4(%rbp), %eax testl %eax, %eax jns .L2 movl -4(%rbp), %eax subl $1, %eax movl %eax, -4(%rbp) .L2: movl -4(%rbp), %eax andl $7, %eax testl %eax, %eax jne .L3 movl -4(%rbp), %eax addl $6, %eax movl %eax, -4(%rbp) .L3: movl -4(%rbp), %eax andl $1, %eax testl %eax, %eax jne .L4 movl -4(%rbp), %eax addl $1, %eax movl %eax, -4(%rbp) jmp .L5 .L4: 0051 8B45FC movl -4(%rbp), %eax 0054 83E801 subl $1, %eax 0057 8945FC movl %eax, -4(%rbp)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.