0% found this document useful (0 votes)
4 views8 pages

Pre 2

The document outlines a lab experiment for the ELE338 Microprocessor Architecture and Programming course at Hacettepe University, focusing on memory and variable operations. It includes three code blocks demonstrating different operations: converting character cases, modifying string outputs, and reversing strings using assembly language. The document also contains student identification details and results from the Emu8086 emulator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Pre 2

The document outlines a lab experiment for the ELE338 Microprocessor Architecture and Programming course at Hacettepe University, focusing on memory and variable operations. It includes three code blocks demonstrating different operations: converting character cases, modifying string outputs, and reversing strings using assembly language. The document also contains student identification details and results from the Emu8086 emulator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR

ARCHITECTURE and PROGRAMMING LAB.


Experiment 2 – Memory and variable operations

Student Name: Muhsin Emre AYGAR

Student No: 2210357027

Quesiton 1:
Code Block

; Muhsin Emre Aygar - 2210357027

.model small
.stack 100h
.data
indata db 11 dup(?) ; 10 + 1 character input data from user
outdata db 11 dup(?) ; Result data after changing the input
prompt db 'Enter 10 characters: $'
newline db 13, 10, 'Output: $'

.code
main:
mov ax, @data
mov ds, ax
mov es, ax

; Show prompt message


lea dx, prompt
mov ah, 09h
int 21h

mov cx, 10 ; Set counter variable


lea di, indata ; Indata variable offset data

get_input:
mov ah, 00h ; Take keyboard input (int 16h)
int 16h
mov [di], al ; Store taking data

; Print entered keyboard input


mov dl, al
mov ah, 02h ; Dos function to write character to stdout
int 21h

inc di
loop get_input

; Change character state


lea si, indata
lea di, outdata
mov cx, 10

; (contiune on PAGE 2)

1
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.
switch_case:
lodsb ; Mov [SI] value to AL register
cmp al, 'a'
jl check_upper
cmp al, 'z'
jg check_upper
sub al, 20h ; Change lower to upper
jmp store_char

check_upper:
cmp al, 'A'
jl store_char
cmp al, 'Z'
jg store_char
add al, 20h ; Change upper to lower

store_char:
stosb ; Mov AL register content to [DI] address
loop switch_case

; Print result
lea dx, newline
mov ah, 09h
int 21h

lea dx, outdata


mov ah, 09h
int 21h

; End Program
mov ah, 4Ch
int 21h

end main

2
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.

Emu8086 Result

3
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.
Quesiton 2:
Code Block
; Muhsin Emre Aygar - 2210357027
.model small
.stack 100h
.data
somewords db "resistor capacitor transistor diode", '$'
newline db 13, 10, '$'
prompt db 'Original Input: $'
result db 'Modified Output: $'

.code
main:
mov ax, @data
mov ds, ax
mov es, ax

; Print original input


lea dx, prompt
mov ah, 09h
int 21h
lea dx, somewords
mov ah, 09h
int 21h

; Newline after original input


lea dx, newline
mov ah, 09h
int 21h
lea si, somewords ; Load the address of 'somewords' into SI
mov bl, 1 ; Indicate that the first character is the start of a word

convert_case:
lodsb ; Load the byte at DS:SI into AL, and increment SI
cmp al, '$' ; Check if end of string
je done ; If yes, jump to done
cmp al, ' ' ; Check if the character is a space
je next_char ; If yes, jump to next_char
cmp bl, 1 ; Check if this character is the start of a word
jne not_word_start ; If no, jump to not_word_start
cmp al, 'a' ; Check if the character is a lowercase letter
jl not_word_start ; If less, it's not a lowercase letter
cmp al, 'z'
jg not_word_start ; If greater, it's not a lowercase letter
sub al, 20h ; Convert lowercase letter to uppercase
mov [si-1], al ; Store the uppercase letter back to the same location

; (contiune on PAGE 5)

4
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.
not_word_start:
mov bl, 0 ; Indicate that we are no longer at the start of a
word
jmp convert_case ; Jump back to convert_case

next_char:
mov bl, 1 ; Indicate that the next character is the start of a word
jmp convert_case ; Jump back to convert_case

done:
; Newline before result output
lea dx, newline
mov ah, 09h
int 21h

; Print modified output


lea dx, result
mov ah, 09h
int 21h

lea dx, somewords


mov ah, 09h
int 21h

; End program
mov ah, 4Ch
int 21h

end main

Emu8086 Result:

5
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.
Quesiton 3:
Code Block

; Muhsin Emre Aygar - 2210357027

.model small
.stack 100h
.data
somewords db "resistor capacitor transistor diode", '$'
newline db 13, 10, '$'
prompt db 'Reversed Output: $'

.code
main:
mov ax, @data
mov ds, ax
mov es, ax

; Print original input


lea dx, prompt
mov ah, 09h
int 21h

; Push characters onto stack


lea si, somewords ; Load the address of 'somewords' into SI
mov di, 0 ; DI is used to keep track of the stack position

push_chars:
lodsb ; Load byte at DS:SI into AL, and increment SI
cmp al, '$' ; Check if end of string
je pop_chars ; If yes, jump to pop_chars
push ax ; Push AL onto stack (using AX register)
jmp push_chars ; Continue to push the next character

pop_chars:
lea di, somewords ; Load the address of 'somewords' into DI
mov bl, 0 ; BL is used to check if stack is empty

; (contiune on PAGE 7)

6
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.

pop_loop:
pop ax ; Pop the top character from stack into AX
mov [di], al ; Store the character into 'somewords'
inc di ; Move to the next position

; Check if stack pointer is at its initial position (not empty)


cmp sp, 100h
jne pop_loop ; If not empty, continue to pop

; Add the end of string character '$'


mov byte ptr [di], '$'

; Newline before result output


lea dx, newline
mov ah, 09h
int 21h

; Print reversed result


lea dx, somewords
mov ah, 09h
int 21h

; End program
mov ah, 4Ch
int 21h

end main

Emu8086 Result:

7
HACETTEPE UNIVERSITY ELECTRICAL AND ELECTRONICS ENGINEERING ELE338 - MICROPROCESSOR
ARCHITECTURE and PROGRAMMING LAB.

My Computer Specifications

You might also like