assembly - Don't understand shifting, rotating, and LAHF -


for example, assignment have

write hla assembly program prompts int8 value inspect , prints in binary format. example, here program output various entered values

gimme decimal value print: 15 15 0000_1111 gimme decimal value print: 7 7 0000_0111 

i able source code of answer i'm having trouble understanding.

i put thought process inside comments

 program binaryoutput;  #include( "stdlib.hhf" );  static    zgivennumber : int8;  // value inspect  begin binaryoutput;     //ask decimal number     stdout.put( "gimme decimal value print: ");     //put number in 'zgivennumber' (let's 7)     stdin.get( zgivennumber );     //put 'zgivennumber' inside 'bh' ('bh' contains 7)     mov( zgivennumber, bh);      stdout.put("number in binary is: ", nl);      //shift left 1 @ 'bh' (this makes 'bh' 14)     shl(1, bh);     //not clue doing     lahf();     //checking see if 0000_0001 , ah match 0's , 1's     //(i'm not sure % sign ah came from)     and( %0000_0001, ah );     //print out 'ah' in 8 bit form     stdout.puti8(ah);      shl(1, bh); //2     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);      shl(1, bh); //next     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);     shl(1, bh); //next     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);     stdout.put("_");     shl(1, bh); //next     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);     shl(1, bh); //next     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);     shl(1, bh); //next     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);     shl(1, bh); //next     lahf();     and( %0000_0001, ah );     stdout.puti8(ah);   end binaryoutput; 

we're not allowed use loops yet.

i guess don't understand shl , lahf part

from understand, lahf means load ah flags. puts flags ah. makes sense that ah coming then. also, shl puts 0 bit 0 , carries on in bit 7 carry flag. i'm not sure means.

lahf loads cpu flags upper byte of ax regishter (ah). bit 0 of flags (and ah after lahf instruction) carry flag. so, if msb of bh 1 after left shift carry set. popping off bits msb lsb bh.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -