I have a question about how to move values around in the x86 Assembly eax register. I know that the 32-bit register breaks down into smaller component registers with the lower 16-bits being ax and that 16- bits breaks down even further into the 8-bit registers ah and al.
I'm currently writing a program for an x86 Assembly Language assignment that wants me to move four 8-bit hex values around in the register using only the mov, add, and sub commands. The program starts by having you shift the values of the variables around by adding and subtracting them, and that's no problem.
The second part (phase2) is to put each of the values into each of the eax 8-bit positions. But, I know you can only access the lower two 8-bit positions ("ah" and "al".) I need to somehow move ah and al together into that leading 16-bits of eax, pushing the values added to ah and al left two-byte positions? (question mark, because I do not know.) I am fairly certain that I can then just add the correct values back to ah and al to finish the solution.
I believe the way to do this is to add 'some hex value' to ah and have that overflow left, but I can't seem to wrap my head around the logic of it. "Logically," I want to say this seems like the best course of action, but I'm not sure how to implement it. And, since I can't wrap my head around it, I can't find the hidden algorithm I'm supposed to find. Phase2 is only supposed to be aprx 21 lines so I know it is not a massive column of add instructions.
Any direction on how to think about this would be highly appreciated. Thanks to whomever.
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
var1 BYTE 'A'
var2 BYTE 'B'
var3 BYTE 'C'
var4 BYTE 'D'
.code
main proc
;phase1
mov al, var1; store 'A'
mov ah, var4; store 'D'
mov var1, ah; move 'D' to var1
sub ah, 1; make ah 'C'
mov var4, ah; move 'C' to var4
sub ah, 1; make ah 'B'
mov var3, ah; move 'B' to var3
mov var2, al; 'mov al to var2
;var1 BYTE 'D'
;var2 BYTE 'A'
;var3 BYTE 'B'
;var4 BYTE 'C'
;phase2
mov ah, var1; store 'D'
mov al, var2; store 'A'
; this is where I want to shift al and ah left two bytes
; once the first two bytes of eax equal 'DA' move 'B' 'C'
; into ah and al
mov ah, var3; store 'B'
mov al, var4; store 'C'
;eax should read 'DABC' = 44414243
invoke ExitProcess,0
main endp
end main