Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following 3 short programs in Assembly language. 1. Multiply any two u

ID: 3667377 • Letter: W

Question

Write the following 3 short programs in Assembly language.

1. Multiply any two unsigned 16-bit numbers in R0, R1, result in R2, using only shift and add instructions, no multiplication instructions

2. Convert any character in R0 from lower-case to upper-case by operating on it, NOT replacing it. The converted character should stay in R0. Hint: See ASCII table

3. Add two signed numbers in R0=0x78013729, R1=0x62029383 and result in R2.

Convert the values from R0, R1, R2 to decimal using 2’s complement. What flags are set? How will you interpret the result?

Explanation / Answer

1.

The short program to multiply two unsigned 16-bit numbers in R0, R1, resulting in R2, using only shift and instructions and having no multiplication instructions is as follows:

[org 0x0100]
jmp start

//16bit multiplicand 32bit space
multiplicand: dd 1300;

//16bit multiplier
multiplier: dw 500;

//32bit result
result: dd 0 ;

//initialize bit count to 16
start: mov cl, 16;

//load multiplier in dx
mov dx, [multiplier];

// move right most bit in carry
checkbit: shr dx, 1;

// skip addition if bit is zero
jnc skip ;

mov ax, [multiplicand]

// add less significant word
add [result], ax;
mov ax, [multiplicand+2]

//add more significant word.
adc [result+2], ax ;

skip: shl word [multiplicand], 1

//shift multiplicand left.
rcl word [multiplicand+2], 1;

//decrement bit count.
dec cl ;

//repeat if bits left.
jnz checkbit ;

// terminate program

mov ax, 0x4c00;

2

The small program to convert any character in R0 from lower-case to upper case by operating on it and not replacing it, is as follows:

.MODEL SMALL
.DATA
        STR1    DB      10 DUP(' '),'$'
        NEW_LINE DB 0DH,'CONVERTED STRING:$','$'
.CODE

MAIN    PROC
        MOV AX,@DATA
        MOV DS,AX

        LEA SI,STR1
AGAIN:
        MOV AH,01H
        INT 21H
        CMP AL,0DH
        JE BACK

        CMP AL,41H
        JL BAK
        CMP AL,5AH
        JG BAK
        ADD AL,20H
BAK:    MOV [SI],AL
        INC SI
        JMP AGAIN
BACK:
        MOV AL,'$'
        MOV [SI],AL

        MOV AH,09H
        LEA DX,NEW_LINE
        INT 21H

        MOV AH,09H
        LEA DX,STR1
        INT 21H

        MOV AH,4CH
        INT 21H

MAIN    ENDP
        END   MAIN

3.

The program to add two signed numbers in R0=0x78013729, R1=0x62029383 is as follows:

//R0 is Constantly 0x78013729

Mov R0, # 0x78013729 ;

//R1 is Constantly 0x62029383

Mov R1, #0x62029383 ;

add it to the value of R0 and R1 like R0+R1 values stored in R0

ADD R0,R1;

addition value moved into R2

MOV R2, R0;

END