Task #1
Introduction to Stack
//Code .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC mov ax, @data mov ds, ax mov ax, 1234h mov bx, 5678h push ax inc ax push ax push bx pop cx pop dx pop cx pushf sub ax,ax popf ENDP MAIN end MAIN
Task #2
Write a code to take an input string and print the string in reverse.
//Code .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC mov ax, @data mov ds, ax mov ah, 2 mov dl, '?' int 21h mov ah, 1 mov cx, 0 label1: int 21h cmp al, 0dh je label2 push ax inc cx jmp label1 label2: mov ah, 2 mov dl, 0ah int 21h mov dl, 0dh int 21h label3: pop dx int 21h loop label3 mov ah, 4ch int 21h ENDP MAIN end MAIN
Task #3
Introduction to procedure
//Code .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC mov ax, @data mov ds, ax mov ax, 1595 mov bx, 2526 call a mov ah, 4ch int 21h ENDP MAIN a PROC add ax, bx ret endp a end MAIN
Task #4
Write a code with a multiply procedure.
//Code .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC mov ax, @data mov ds, ax mov ax, 2 mov bx, 3 call multiply mov ah, 4ch int 21h ENDP MAIN multiply PROC push ax push bx xor dx, dx repeat: test bx, 1 jz endif add dx, ax endif: shl ax, 1 shr bx, 1 jnz repeat pop bx pop ax ret endp multiply end MAIN
Task #5
Multiplication procedure by addition
//Code .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC mov ax, @data mov ds, ax mov ax, 2 mov bx, 30 call multiply mov ah, 4ch int 21h ENDP MAIN multiply PROC push ax push bx push cx mov cx, bx xor dx, dx top: add dx, ax loop top pop cx pop bx pop ax ret endp multiply end MAIN
Task #6
Multiply and division instruction
//Code .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC mov ax, @data mov ds, ax mov ax, 2 mov bx, 0FFFFh mul bx imul bx div bx idiv bx mov ah, 4ch int 21h ENDP MAIN end MAIN
Task #7
Write a program that prompts user to enter 2 binary numbers upto 8 digits each, and print their sum in the next line in binary. If the user enters illegal character, the user should be prompted to begin again. Each input ends withj a carriage return.
Sample execution: Type a binary number, upto 8 digits: 11001010 Type a binary number, upto 8 digits: 10011100 The binary sum is 101100110
//Code To be done by students
Homework
- Chapter 7 Problem 9
- Chapter 7 Problem 10
- Chapter 7 Problem 11
- Chapter 7 Problem 13
- Chapter 7 Problem 14