Podstrony
- Strona startowa
- Conrad Joseph Wsrod pradow (SCAN dal 946)
- Farrel Joseph P. Wojna nuklearna sprzed 5 tysicy lat
- Conrad Joseph Zlota strzala (SCAN dal 767)
- Joseph P. Farrell Wojna nuklearna sprzed 5 tysięcy lat (2)
- Joseph O'Connor The Structure Of Musical Talent (NLP)
- Campbell Joseph The Masks Of God Primitive Mythology
- Conrad Joseph Tajfun i inne opowiadania
- Gabriel Richard A. Scypion Afrykański Starszy największy wódz starożytnego Rzymu
- Auel Jean M Rzeka powrotu (SCAN dal 948)
- Koneczny.Feliks Cywilizacja zydowska
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- orla.opx.pl
[ Pobierz całość w formacie PDF ]
.3 Determine the result of each instruction for the following program segment:PUSH EBP Push EBPStackMOV EBP, ESP Move ESP to EBPPUSH EAX Push EAXLowPUSH EBX Push EBXPUSH ECX Push ECXESPECX.MOV EAX, [EBP 12] Move ECX to EAXEBXMOV EBX, [EBP 8] Move EBX to EBXEAXMOV ECX, [EBP 4] Move EAX to ECXEBP=ESPEBP.ESPADD ESP, 12 Restore ESPPOP EBP Restore EBPHigh7.5 The partial contents of a stack are shown below before execution of the pro-gram segment listed below.Determine the contents of the stack after the pro-gram has been executed and indicate the new top of stack.Stack Before Stack AfterLow High Low addr Low High Low addrESP E4 11 ESP E4 F57E 00 7E 00High addr High addrPOP BX ;BX = 11 E4 HMOV AH, BH ;AX = 11 HADD AH, BL ;AX = F5 (E4 + 11 = F5)MOV BH, AH ;BX = F5 E4 H BL = E4PUSH BX ;Stack = E4 F5 H Low addr = E4700 Appendix B Answers to Select Problems7.8 Write an assembly language program using the PUSH and POP instruc-tions that adds four decimal integers, then displays their sum.Embed theassembly module in a C program.The decimal integers are entered from thekeyboard.//push_pop_add_int.cpp//add four decimal integers using push and pop#include "stdafx.h"int main (void){//define variablesint dec1, dec2, dec3, dec4, sum_1234;printf ("Enter four decimal integers: \n");scanf ("%d %d %d %d", &dec1, &dec2, &dec3, &dec4);//switch to assembly_asm{MOV EAX, dec1MOV EBX, dec2ADD EAX, EBX ;dec1 + dec2 -> EAXPUSH EAX ;push dec1 + dec2MOV EAX, dec3MOV EBX, dec4ADD EAX, EBX ;dec3 + dec4 -> EAXPOP EBX ;pop dec1 + dec2ADD EAX, EBX ;total sum -> EAXMOV sum_1234, EAX ;move sum to result area}printf ("\nsum of four integers = %d\n\n",sum_1234);return 0;} Chapter 7 Stack Operations 701Enter four decimal integers:1 2 3 4sum of four integers = 10Press any key to continue._-----------------------------------------------------Enter four decimal integers:25 50 75 100sum of four integers = 250Press any key to continue._-----------------------------------------------------Enter four decimal integers:1000 2000 3000 4000sum of four integers = 10000Press any key to continue._-----------------------------------------------------Enter four decimal integers:37 1200 750 875sum of four integers = 2862Press any key to continue._702 Appendix B Answers to Select ProblemsChapter 8 Logical, Bit, Shift, and RotateInstructions8.3 Using only logic instructions, write one instruction for each of the followingparts that will perform the indicated operations.(a) Set the low-order four bits of register AX.OR AX, 000FH(b) Reset the high-order three bits of register AX.AND AX, 1FFFH(c) Invert bits 7, 8, and 9 of register AX.XOR AX, 0380H8.8 Write an assembly language module embedded in a C program that uses thebit scan forward (BSF) instruction to detect whether the first bit detected is inthe low-order half or the high-order half of a 32-bit operand.Do not deter-mine the bit position.//bsf_if_struc.cpp//determine if first bit is in position 15//using an if structure#include "stdafx.h"int main (void){//define variablesint bsf_src_opnd;printf ("Enter an 8-digit hexadecimal number: \n");scanf ("%X", &bsf_src_opnd);//continued on next page Chapter 8 Logical, Bit, Shift, and Rotate Instructions 703//switch to assembly_asm{MOV EBX, bsf_src_opndCMP EBX, 0JZ NO_ONESBSF EAX, EBXCMP EAX, 15JBE LESS_THAN_16JMP GREATER_THAN_15}NO_ONES:printf ("\nBSF opnd has no 1s\n\n");goto end;LESS_THAN_16:printf ("\nBit is in position 15 -- 0\n\n");goto end;GREATER_THAN_15:printf ("\nBit is in position 31 -- 16\n\n");end:return 0;}Enter an 8-digit hexadecimal number:00A07000Bit is in position 15 -- 0Press any key to continue._------------------------------------------------------Enter an 8-digit hexadecimal number:7BC68000Bit is in position 15 -- 0Press any key to continue._------------------------------------------------------//continued on next page704 Appendix B Answers to Select ProblemsEnter an 8-digit hexadecimal number:FFFF0001Bit is in position 15 -- 0Press any key to continue._------------------------------------------------------Enter an 8-digit hexadecimal number:80D10000Bit is in position 31 -- 16Press any key to continue._------------------------------------------------------Enter an 8-digit hexadecimal number:0DC00000Bit is in position 31 -- 16Press any key to continue._------------------------------------------------------Enter an 8-digit hexadecimal number:80000000Bit is in position 31 -- 16Press any key to continue._------------------------------------------------------Enter an 8-digit hexadecimal number:00000000BSF opnd has no 1sPress any key to continue._8.12 Determine the contents of register EBX and the flags register after executionof the program segment shown below.Then write an assembly languagemodule embedded in a C program to verify the results.MOV EBX, 0FFFFA85BHSAL EBX, 20MOV EBX, 0FFFFA85BHSAR EBX, 20SAL result = 85B00000 SAR result = FFFFFFFFSAL flags = 86 SAR flags = 87 Chapter 8 Logical, Bit, Shift, and Rotate Instructions 705//sal_sar.cpp//program to illustrate shift arithmetic left//and shift arithmetic right instructions//for the same operand#include "stdafx.h"int main (void){//define variablesint dst_opnd, sal_rslt, sar_rslt;unsigned char sal_flags, sar_flags;printf ("Enter an 8-digit hexadecimal number: \n");scanf ("%X", &dst_opnd);//switch to assembly_asm{//SAL instructionMOV EBX, dst_opndSAL EBX, 20MOV sal_rslt, EBXLAHFMOV sal_flags, AH//SAR instructionMOV EBX, dst_opndSAR EBX, 20MOV sar_rslt, EBXLAHFMOV sar_flags, AH}printf ("\nSAL result = %X\nSAL flags = %X\n\n",sal_rslt, sal_flags);printf ("\nSAR result = %X\nSAR flags = %X\n\n",sar_rslt, sar_flags);return 0;}706 Appendix B Answers to Select ProblemsEnter an 8-digit hexadecimal number:FFFFA85BSAL result = 85B00000SAL flags = 86SAR result = FFFFFFFFSAR flags = 87Press any key to continue._8.14 Write an assembly language module embedded in a C program that will mul-tiply and divide a decimal number by eight using arithmetic shift instruc-tions.When dividing, some numbers will have the fraction truncated.//sal_sar_2.cpp//shifting positive and negative numbers//using SAL and SAR instructions#include "stdafx
[ Pobierz całość w formacie PDF ]