題目:下面的程式執行後,ax的值是多少?
assume cs:codesg<br />datasg segment<br />db 16 dup(0)<br />datasg ends<br />codesg segment<br /> start:<br /> mov ax,0<br /> push ax<br /> popf</p><p> mov ax,0fff0h<br /> add ax,0010h</p><p> pushf<br /> pop ax<br /> and al,11000101b<br /> and ah,00001000b</p><p> mov ax,4c00h<br /> int 21h</p><p> codesg ends<br /> end start
解析:
assume cs:codesg<br />datasg segment<br />db 16 dup(0)<br />datasg ends<br />codesg segment<br /> start:<br /> mov ax,0<br /> push ax<br /> popf;把0賦值給標誌寄存器,即把其所有標誌位清零</p><p> mov ax,0fff0h<br /> add ax,0010h;執行此加法運算後,ax的值為0,但是產生了進位,且有0(偶數)個1。所以pf=1、zf=1、cf=1,所以標誌寄存器中的值就是0045h,但是在調試時卻是0047h,不明白為什嗎?</p><p> pushf<br /> pop ax;把標誌寄存器的值給ax,即ax=0045h<br /> and al,11000101b;al的值45h魚器and後還是45h<br /> and ah,00001000b;由於ah的值為0,所以ah and之後的值就是0</p><p> mov ax,4c00h<br /> int 21h</p><p> codesg ends<br /> end start
所以ax的值為0045h