2021
1. Discuss the comparison of assembly language and high-level
language with the help of some applications.
2. An effective way to explain how a computer's hardware and
software are related is called the virtual machine concept.
Discuss this concept.
Virtual Machine Concept
The Virtual Machine (VM) concept is a foundational idea in computer organization that helps
explain the relationship between hardware and software. It provides a model for how software
can interact with computer hardware in a layered and abstracted manner. This concept is
extensively described by Andrew Tanenbaum in his book Structured Computer Organization.
Basic Idea
At the most fundamental level, a computer executes programs written in machine language, also
known as Level 0 (L0). This language consists purely of binary instructions that the hardware
can directly execute. However, programming in L0 is extremely complex and error-prone due to
its low-level nature.
To ease programming efforts, higher-level languages are introduced. These languages are not
directly executable by the hardware and need to be either:
1. Interpreted – Each instruction is decoded and executed one by one by a program written
in machine language.
2. Translated – The entire program is converted into machine code before execution.
Virtual Machines
Instead of just thinking in terms of languages, the virtual machine concept describes each
abstraction level as a virtual computer, or virtual machine.
Virtual Machine (VM1) runs programs written in language L1.
VM0 runs programs written in L0 (the hardware-level machine language).
Each virtual machine can be implemented either in hardware or software. Software that emulates
a machine's behavior enables programs written for higher-level VMs to run on lower-level
hardware.
This concept can be extended to multiple levels (VM2, VM3, ..., VMn), each providing a higher
level of abstraction and easier programming models. The topmost virtual machine level typically
supports high-level programming languages like C++, Python, or Java.
Java as an Example
A real-world example of the virtual machine concept is the Java Virtual Machine (JVM).
When a Java program is compiled, it is translated into an intermediate code called Java
bytecode. This bytecode is not run directly on the hardware but by the JVM, which interprets or
compiles it further to native machine instructions.
This makes Java programs platform-independent, since the same bytecode can run on
any system that has a JVM.
Levels of Virtual Machines in Modern Computers
Here’s how various virtual machines and programming levels relate to actual computer
architecture:
1. Level 0 (Hardware/Logic Circuits)
o Executes binary instructions.
o Language: Native machine code (L0).
2. Level 1 (Microprogramming)
o Some processors interpret instructions using microcode.
3. Level 2 (Instruction Set Architecture - ISA)
o Defines the set of operations (ADD, MOV, SUB, etc.) the CPU understands.
o Still very low level; machine language instructions are executed directly.
4. Level 3 (Assembly Language)
o Uses mnemonics like MOV, ADD, SUB.
o Easier than binary but still hardware-specific.
o Requires an assembler to convert to machine code.
5. Level 4 (High-Level Languages)
o Languages like C, C++, Java allow development of complex software.
o These are compiled into machine code or bytecode (in Java’s case).
Advantages of the Virtual Machine Concept
Abstraction: Each level hides unnecessary details from the programmer.
Portability: Programs can be written once and run anywhere (e.g., Java).
Security: VMs like the JVM can provide controlled environments for execution.
Ease of development: Programmers can work in user-friendly languages, while lower
levels handle hardware interaction.
3. Write a short assembly language program that adds and
subtracts integers. Registers should be used hold the
intermediate data, and call a library subroutine to display the
contents of the registers on the screen.
.386
.model flat,stdcall
.stack 4096
INCLUDE Irvine32.inc
.code
main PROC
; Load initial values into registers
mov eax, 15 ; First number
mov ebx, 5 ; Second number
add eax, ebx ; EAX = 15 + 5 = 20
; Dump register contents after addition
call DumpRegs
sub eax, ebx ; EAX = 20 - 5 = 15
; Dump register contents after subtraction
call DumpRegs
exit
main ENDP
END main
4. Discuss INC, SUB, LOOP, and PUSH instructions with the help of
some programming examples
In x86 Assembly Language, various instructions control data manipulation, flow
control, and memory operations. The INC, SUB, LOOP, and PUSH instructions are
commonly used for arithmetic operations, loops, and stack management. Below is
a detailed discussion of each with examples:
1. INC Instruction (Increment)
The INC instruction increases the value of a register or memory location by 1. It
does not affect the Carry Flag (CF), but it updates the Overflow (OF), Zero (ZF),
Sign (SF), Auxiliary Carry (AF), and Parity (PF) flags.
Syntax:
INC reg/mem
Example:
.data
myWord WORD 1000h
.code
inc myWord ; myWord becomes 1001h
mov bx, myWord
dec bx ; BX becomes 1000h again
This instruction is useful in counting operations, such as traversing arrays or
managing loop counters.
2. SUB Instruction (Subtraction)
The SUB instruction subtracts a source operand from a destination operand and
stores the result in the destination. It affects all status flags including CF, ZF, SF,
OF, AF, and PF.
Syntax:
SUB dest, source
Example:
.data
var1 DWORD 30000h
var2 DWORD 10000h
.code
mov eax, var1 ; EAX = 30000h
sub eax, var2 ; EAX = 20000h
The instruction is widely used in arithmetic operations and comparisons.
3. LOOP Instruction
The LOOP instruction uses the ECX register as a loop counter. Each time it is
executed, ECX is decremented. If ECX is not zero, control jumps to the specified
label; otherwise, the next instruction is executed.
Syntax:
LOOP destination
Example (Adding 1 to AX five times):
.code
mov ax, 0
mov ecx, 5
L1:
inc ax
loop L1 ; Repeats until ECX = 0
Key Notes:
LOOP automatically decrements ECX.
Jump is taken only if ECX ≠ 0.
ECX should be initialized properly to avoid infinite loops.
4. PUSH Instruction (Stack Operation)
The PUSH instruction is used to place data onto the stack. It first decrements the
ESP (Stack Pointer) and then stores the value at the new stack location. It
supports registers, memory operands, and immediate values.
Syntax:
PUSH reg/mem16
PUSH reg/mem32
PUSH imm32
Example:
.code
mov eax, 1234h
push eax ; Pushes 1234h onto the stack
In 32-bit mode, PUSH decreases ESP by 4 bytes.
It is useful for saving register values or passing parameters to functions.