0% found this document useful (0 votes)
51 views13 pages

Name: Haris Shabbir Section:3B SAP ID: 70077931

This document contains the responses to assignment questions for a computer organization and assembly language course. It includes answers to multiple choice and numerical questions about binary arithmetic, flags, data types, addressing modes, instruction sets, and assembly language programming. The assignments cover topics like binary operations, data representation, assembly language programming, and machine level programming.

Uploaded by

Haris Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views13 pages

Name: Haris Shabbir Section:3B SAP ID: 70077931

This document contains the responses to assignment questions for a computer organization and assembly language course. It includes answers to multiple choice and numerical questions about binary arithmetic, flags, data types, addressing modes, instruction sets, and assembly language programming. The assignments cover topics like binary operations, data representation, assembly language programming, and machine level programming.

Uploaded by

Haris Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

NAME: HARIS SHABBIR

SECTION:3B

SAP ID: 70077931

COMPUTER ORGANIZATION AND


ASSEMBLY LANGUAGE
ASSIGNMENT 3 COAL

QUESTION 1

(a) BH = 84, CF = 0 (no carry), ZF = 0 (result not zero), AF = 1 (auxiliary carry)

(b) CX = 79F1, CF = 0 (no carry), ZF = 0 (result not zero), AF = 1 (auxiliary carry)

(c) AX = 0100, CF = 0 (no carry), ZF = 0 (result not zero), AF = 1 (auxiliary carry)

(d) BL = 00, CF = 1 (carry), ZF = 1 (result is zero), AF = 1 (auxiliary carry)

(e) CX = 0000, CF = 1 (carry), ZF = 1 (result is zero), AF = 1 (auxiliary carry)

(f) AH = FF, CF = 0 (no carry), ZF = 0 (result not zero), AF = 0 (no auxiliary carry)

QUESTION 2
The data is stored with directive DW. The program will loop 8 times to add the 8 words, and the
loop count is set in data item COUNT, then moved to CX. SI is used to point to the data. As each
word is added to AX, any carry that was generated is added to BX, then the result is stored with
BX as the higher word and AX as the lower word. In this particular example, the result of the
addition is 5CE4H, no carries were generated so the higher word (BX) = 0.

TITLE PROB2 (EXE) ADDING 8 WORDS

PAGE 60,132

STSEG SEGMENT

DB 64 DUP (?)

STSEG ENDS

;----------------------------

DTSEG SEGMENT
COUNT EQU 08

DATA DW 2300,4300,1200,3700,1298,4323,5673,986

ORG 0010H

SUM DW 2 DUP(?)

DTSEG ENDS

;----------------------------

CDSEG SEGMENT

MAIN PROC FAR

ASSUME CS: CDSEG, DS: DTSEG, SS: STSEG

MOV AX, DTSEG

MOV DS, AX

MOV CX,COUNT ;CX is the loop counter

MOV SI,OFFSET DATA ;SI is the data pointer

MOV AX,00 ;AX will hold the sum

MOV BX,AX ;BX will hold the carries

BACK: ADD AX,[SI] ;add the next word to AX

ADC BX,0 ;add carry to BX

INC SI ;increment data pointer twice

INC SI ; to point to next word

DEC CX ;decrement loop counter

JNZ BACK ;if not finished, continue adding

MOV SUM,AX ;store the sum

MOV SUM+2,BX ;store the carries


MOV AH,4CH

INT 21H ;go back to DOS

MAIN ENDP

CDSEG ENDS

END MAIN

QUESTION 3
In order to rewrite Program 3-2 for multibyte addition, the following changes were made:

(1) CX was changed from 4 (to add 4 words) to 8 (to add 8 bytes)

(2) AL was used to accumulate the sum of the two bytes instead of AX

(3) BYTE PTR was used to make the operands match in size

(4) all pointers SI, DI and BX were incremented once to point to the next byte instead of twice
to point to the

next word

The result of the addition is 945D09387874H.

TITLE PROB3 (EXE) MULTIBYTE ADDITION

PAGE 60,132

STSEG SEGMENT

DB 64 DUP (?)

STSEG ENDS

;----------------------------

DTSEG SEGMENT

DATA1 DQ 548FB9963CE7H
ORG 0010H

DATA2 DQ 3FCD4FA23B8DH

ORG 0020H

DATA3 DQ ?

DTSEG ENDS

;----------------------------

CDSEG SEGMENT

MAIN PROC FAR

ASSUME CS:CDSEG,DS:DTSEG,SS:STSEG

MOV AX,DTSEG

MOV DS,AX

CLC ;clear carry before first addition

MOV SI,OFFSET DATA1 ;SI is pointer for operand1

MOV DI,OFFSET DATA2 ;DI is pointer for operand2

MOV BX,OFFSET DATA3 ;BX is pointer for the sum

MOV CX,08 ;CX is the loop counter

BACK: MOV AL,BYTE PTR[SI] ;move the first operand to AX

ADC AL,BYTE PTR [DI] ;add the second operand to AX

MOV BYTE PTR [BX],AL ;store the sum

INC SI ;point to next byte of operand1

INC DI ;point to next byte of operand2

INC BX ;point to next byte of sum

LOOP BACK ;if not finished, continue adding


MOV AH,4CH

INT 21H ;go back to DOS

MAIN ENDP

CDSEG ENDS

END MAIN

QUESTION 4
This program subtracts one 8-byte number from another. The subtraction is performed one byte
at a time, starting at the least significant byte. SBB is used to take care of any borrow that
occurred from the previous byte subtraction. The result of the subtraction is 14C269F4015AH.

The program is on the following page.

TITLE PROB4 (EXE) MULTIBYTE SUBTRACTION

PAGE 60,132

STSEG SEGMENT

DB 64 DUP (?)

STSEG ENDS

;----------------------------

DTSEG SEGMENT

DATA1 DQ 548FB9963CE7H

ORG 0010H

DATA2 DQ 3FCD4FA23B8DH

ORG 0020H

DATA3 DQ ?

DTSEG ENDS
;----------------------------

CDSEG SEGMENT

MAIN PROC FAR

ASSUME CS:CDSEG,DS:DTSEG,SS:STSEG

MOV AX,DTSEG

MOV DS,AX

CLC ;clear carry before first subtraction

MOV SI,OFFSET DATA1 ;SI is pointer for operand1

MOV DI,OFFSET DATA2 ;DI is pointer for operand2

MOV BX,OFFSET DATA3 ;BX is pointer for the result

MOV CX,08 ;CX is the loop counter

BACK: MOV AL,BYTE PTR [SI] ;move the first operand to AX

SBB AL,BYTE PTR [DI] ;add the second operand to AX

MOV BYTE PTR [BX],AL ;store the result

INC SI ;point to next byte of operand1

INC DI ;point to next byte of operand2

INC BX ;point to next byte of sum

LOOP BACK ;if not finished, continue subtracting

MOV AH,4CH

INT 21H ;go back to DOS

MAIN ENDP

CDSEG ENDS

END MAIN
QUESTION 5
The three steps are:

(1) convert the subtrahend to two's complement

(2) add the two numbers

(3) invert the carry

(a) 23H 0010 0011 0010 0011

- 12H 0001 0010 1110 1110 step 1: two's complement

11H 0001 0001 step2 : add the two

step 3: invert carry CF=0

(b) 43H 0100 0011 0100 0011

- 51H 0101 0001 1010 1111 step1: two's complement

F2H 1111 0010 step 2: add the numbers

step 3: invert carry CF = 1

(c) 99 0110 0011 0110 0011

- 99 0110 0011 1001 1101 step 1:two's complement

00 0000 0000 step 2: add the numbers

step 3: invert carry CF = 0


QUESTION 6
(1) parts a, b, and c were combined into one program, shown below:
(a) byte1 x byte2 BYTE1 is moved into AL, then AL is multiplied by BYTE2,the product
(59D8H) is
left is AX.
(b) byte1 x word1 BYTE1 is moved into AL and AH is set to zero, then AX is multiplied by
WORD1
and the product, 231694H, is in DX AX, DX = 0023 and AX = 1694.
(c) word1 x word2 WORD1 is moved into AX, then AX is multiplied by WORD2 and the
product,
2DC468H, is in DX AX, DX = 002D and AX = C468.
TITLE PROB61 (EXE) MULTIPLICATION
PAGE 60,132
STSEG SEGMENT
DB 64 DUP (?)
STSEG ENDS
;----------------------------
DTSEG SEGMENT
BYTE1 DB 230
BYTE2 DB 100
WORD1 DW 9998
WORD2 DW 300
DTSEG ENDS
;----------------------------
CDSEG SEGMENT
MAIN PROC FAR
ASSUME CS:CDSEG,DS:DTSEG,SS:STSEG
MOV AX,DTSEG
MOV DS,AX
;(a) byte1 x byte2
MOV AL,BYTE1
MUL BYTE2 ;RESULT IN AX
;(b) byte1 x word1
SUB AH,AH
MOV AL,BYTE1
MUL WORD1 ;RESULT IN DX AX
;(c) word1 x word2
MOV AX,WORD1
MUL WORD2 ;RESULT IN DX AX
MOV AH,4CH
INT 21H ;go back to DOS
MAIN ENDP
CDSEG ENDS
END MAIN
16
(2) parts a, b, and c were combined into one program, shown below:
(a) BYTE1 is moved into AL and AH is set to zero, then AL is divided by BYTE2 and the result
(2H) is in
AL, with the remainder (0) in AH.
(b) WORD1 is moved into AX and DX is set to zero, then AX is divided by WORD2and the
result (21) is
in AX and the remainder (62)is in DX.
(c) DBLWORD is moved into DX AX with DX = 0001 and AX = 86A0, then DX AX is divided
by
BYTE1 which is moved into BL (36H) with BH set to zero;
the result (1B2H) is in AX with DX = B4H, the remainder.
TITLE PROB62 (EXE) DIVISION
PAGE 60,132
STSEG SEGMENT
DB 64 DUP (?)
STSEG ENDS
;----------------------------
DTSEG SEGMENT
BYTE1 DB 230
BYTE2 DB 100
WORD1 DW 9998
WORD2 DW 300
DBLWRD DD 100000
DTSEG ENDS
;----------------------------
CDSEG SEGMENT
MAIN PROC FAR
ASSUME CS:CDSEG,DS:DTSEG,SS:STSEG
MOV AX,DTSEG
MOV DS,AX
;(a) byte1 / byte2
MOV AL,BYTE1
SUB AH,AH
DIV BYTE2 ;QUOTIENT IN AL REM IN AH
;(b) word1 / word2
MOV AX,WORD1
SUB DX,DX
DIV WORD2 ;QUOTIENT IN AX REM IN DX
;(c) dblwrd / byte1
MOV SI,OFFSET DBLWRD
MOV AX,[SI]
MOV DX,[SI+2]
SUB BH,BH
MOV BL,BYTE1
DIV BX ;QUOTIENT IN AX REM IN DX
MOV AH,4CH
INT 21H ;go back to DOS
MAIN ENDP
CDSEG ENDS
END MAIN

QUESTION 7
(a) DX = E000 CF = 1 ZF = 0
(b) DH = F7 CF = 0 ZF = 0
(c) AL = 76 CF = 0 ZF = 0
(d) DX = E390 CF = 0 ZF = 0
(e) AX = 0 CF = 0 ZF = 1
(f) BX = F7D6 CF = 0 ZF = 0
(g) AH = F0 CF = 0 ZF = 0
(h) AX = F999 CF = 0 ZF = 0
(i) DX = 0D7E CF = 0 ZF = 0
(j) BX = 0000 CF = 0 ZF = 1
(k) AL = 00 CF = 0 ZF = 1
(l) DX = 71C8 CF = 0 ZF = 0
(m) DL = 12 CF = 0 ZF = 0
(n) BX = 8AC0 CF = 0 ZF = 0
(o) DX = E400 CF = 0 ZF = 0
QUESTION 8
(a) CF = 0 and ZF = 0, because 2500 > 1400
(b) CF = 0 and ZF = 0, because FF > 6F
(c) CF = 1 and ZF = 0, because 34 < 88
(d) CF = 0 and ZF = 1, because 0 = 0
(e) CF = 1 and ZF = 0, because 0 < FFFF
(f) CF = 0 and ZF = 1, because FFFF = FFFF
(g) CF = 0 and ZF = 0, because 4000 > 2378
(h) CF = 0 and ZF = 1, because 0 = 0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy