Author Topic: Assembly lab pls help- ı have limited time :(  (Read 161 times)

medusa123

  • Regular Member
  • *
  • Posts: 1
Assembly lab pls help- ı have limited time :(
« on: September 04, 2020, 04:38:23 PM »
1. You should add a loop to the lab3.asm program. In detail, this loop should repeat the program over and over again unless the user inputs 'Y' letter at the end of the program.
Hint: You can examine the sample work that we done in the lab hour. There is a BACK2: jump point that starts the program over again. For now, it is working in a infinite way because of the jump command JMP BACK2.
You can utilize this JMP BACK2 into something else by using any type of jumps such as JA, JB or JE. IF you tie this jump with a CMP command for letter 'Y', you can solve this problem. If you need further help, you can always check more at panopto recordings.

2. For now, lab3.asm program reads only ten letters due to counter of CX register represented as MOV CX,10 in the code. This CX counter works with LOOP LOOP1.
You are asked to add a dynamic feature to the program that length of the input string should be calculated after it is typed. To tackle this problem, we constructed a dynamic string length finder located in the loop LOOP2.
Inside this LOOP2 we have saved the length of the string in the BH register. Now, your task is to use BH register value instead of CX register value.
Hint: To replace CX with BX value, you should change LOOP LOOP1 in a way that it should decrement BX register value in each iteration. You should also check whether BX register value reached 0 value or not.
If BX register reaches 0, you can terminate the loop. To check something in the program we generally use if clause that is CMP in the assembly language.For example CMP BX,0 can be interpreted as 'is BX register equal to 0?'.

STACK_SEG SEGMENT STACK USE16
 DB 100 DUP(?)
STACK_SEG ENDS

DATA_SEG SEGMENT 'DATA' USE16
MESSAGE DB 'CE302 LAB2',0DH,0AH
 DB 'PLEASE ENTER YOUR NAME (STRING) FROM KEYBORD: $'
OUTMSG DB 0DH,0AH,'YOUR NAME IS: $'
INSTRING DB 80,?,80 DUP('$') ; xxADSVXZXVZ$$$$$$$$...$;
NEWLINE DB 0DH,0AH,'$'
UPPERCASEM DB 'Uppercase $'
LOWERCASEM DB 'Lowercase $'
DATA_SEG ENDS

CODE_SEG SEGMENT PARA 'CODE' PUBLIC USE16
ASSUME CS:CODE_SEG, DS:DATA_SEG, SS:STACK_SEG
MAIN PROC FAR
 PUSH DS ;INITIATE THE PROGRAM
 XOR AX,AX
 PUSH AX
 MOV AX,DATA_SEG
 MOV DS,AX
 
 BACK2: ; global loop infinite times
 
 MOV AH,0AH     ;input string
 LEA DX,INSTRING
 INT 21H
 
 
 XOR BH,BH ; BH=0
 LEA DI,INSTRING+2
 LOOP2:  ; string length finder
 MOV DL,[DI]
 INC DI
 INC BH
 CMP DL,24H ; is it equal to $ ? , $ symbol denoted as is end of file (EOF)
 JNE LOOP2
 
 LEA DI,INSTRING+2
 MOV CX,10  ; counter
 
 LOOP1:
 MOV BL,[DI]
 
 CMP BL,41H  ; A symbol
 JB LOWERCASE
 CMP BL,5AH  ; Z symbol
 JA LOWERCASE
 
 ADD BL,20H  ; UPPERCASE TO LOWERCASE
 MOV [DI],BL
 INC DI
 
 LOOP LOOP1 ; until CX 0 repeat it
 JMP ENDPROGRAM ;terminate loop after CX is 0
 
 LOWERCASE: ; letters that detected as lowercase

 SUB BL,20H  ; LOWERCASE TO UPPERCASE
 MOV [DI],BL
 INC DI
 
 LOOP LOOP1 ; until CX 0 repeat it
 ENDPROGRAM: ;terminate loop after CX is 0
 
 LEA DX,INSTRING+2 ;PRINT STRING
 MOV AH,9
 INT 21H
 
 JMP BACK2 ; infinite loop
 
 RET
MAIN ENDP
CODE_SEG ENDS
END MAIN

TouEnMasm

  • Member
  • *****
  • Posts: 1344
    • EditMasm
Re: Assembly lab pls help- ı have limited time :(
« Reply #1 on: September 04, 2020, 11:04:55 PM »
Hello,
Quote
CMP BX,0 can be interpreted as 'is BX register equal to 0?'.
CMP BX,0 is machine instruction.Result is describe in an intel or amd instructions guide.
is BX register equal to 0 is a compiler code, The compiler can interpret this and made a different macheine code than CMP BX,0 (probably not)
The answer at your question could be only give by a disassembler of any kind.Dumpbin for example.

Fa is a musical note to play with CL

raymond

  • Member
  • **
  • Posts: 244
    • Raymond's page
Re: Assembly lab pls help- ı have limited time :(
« Reply #2 on: September 05, 2020, 02:58:50 AM »
Quote
in a way that it should decrement BX register value in each iteration. You should also check whether BX register value reached 0 value or not.

EVEN BETTER! Whenever you decrement a register (any register), the ZERO flag gets set immediately if that register reaches 0. There is no need to do a separate comparison to verify if it has reached 0! You simply branch based on the status of the ZERO flag immediately after the decrement instruction.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

daydreamer

  • Member
  • *****
  • Posts: 1360
  • building nextdoor
Re: Assembly lab pls help- ı have limited time :(
« Reply #3 on: September 05, 2020, 10:32:59 PM »
Quote
in a way that it should decrement BX register value in each iteration. You should also check whether BX register value reached 0 value or not.

EVEN BETTER! Whenever you decrement a register (any register), the ZERO flag gets set immediately if that register reaches 0. There is no need to do a separate comparison to verify if it has reached 0! You simply branch based on the status of the ZERO flag immediately after the decrement instruction.
also good to know when you dont need speedy innerloop dec/inc,but slow loop with several millisecond api calls,dec/inc memvariable also sets zero flag,or other countdown variable use
 
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)