+ 1
Assembly language
Please how can you interchange the second digit with the third digit in a four digit number in assembly language?
4 Answers
+ 3
Create a file, mycode.asm, test it by assemble, link and run the exe files nasm -f win32 mycode.asm:
; Load data, 1234 in the EAX register
mov eax, 1234
; Extract the second and third digits
mov ebx, eax ; copy the number to EBX
and ebx, 0xF00 ; mask to isolate the third digit
shr ebx, 8 ; shift the third digit into the lower bits
and eax, 0xF0 ; mask to isolate the second digit
shr eax, 4 ; shift the second digit into the lower bits
; Exchange the values of the second and third digits
xor eax, ebx ; XOR the second and third digits
; Mask the original number to clear the second and third digits
and ecx, eax ; copy the number to ECX
not ecx ; invert the bits of ECX
and ecx, 0xFFF0 ; mask to clear the second and third digits
or ecx, eax ; OR the modified second and third digits into the original number
; ECX now contains the four-digit number with the exchanged second and third digits
+ 2
I am not very well versed in assembly, but I have learned that looking at others code can help in the learning process. If you can solve it using C you can put your C code into www.godbolt.org and look at a possible solution in assembly.
Here is a way in C:
https://code.sololearn.com/cqSPW6JUyk3t/?ref=app
+ 2
Asm in C program,
https://code.sololearn.com/c9Lt0Miq3TXK/?ref=app
0
Thank you , this will really help. Please will it be a similar format if you are changing the first two digits with the last two. Asin 7320 changes to 2073