Pre 2
Pre 2
Quesiton 1:
Code Block
.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
get_input:
mov ah, 00h ; Take keyboard input (int 16h)
int 16h
mov [di], al ; Store taking data
inc di
loop get_input
; (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
; 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
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
; 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
.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
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
; 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